Compare commits
5 Commits
master
...
kern_tomca
| Author | SHA1 | Date |
|---|---|---|
|
|
bcb46819d0 | 1 day ago |
|
|
5e387574b9 | 1 day ago |
|
|
c9b4656eab | 1 week ago |
|
|
42aa7e6f44 | 2 weeks ago |
|
|
4a89c6ec82 | 4 months ago |
2056 changed files with 945920 additions and 165923 deletions
@ -1,31 +1,35 @@ |
|||||||
package de.memtext.baseobjects; |
package de.memtext.baseobjects; |
||||||
|
|
||||||
/** |
/** |
||||||
* |
* |
||||||
* @author MB |
* @author MB |
||||||
* */ |
* */ |
||||||
public class ActivatableItem implements ActivatableItemI { |
public class ActivatableItem implements ActivatableItemI { |
||||||
private static final long serialVersionUID = 1; |
private static final long serialVersionUID = 1; |
||||||
private boolean isActive; |
|
||||||
/** |
private boolean isActive; |
||||||
* |
|
||||||
*/ |
/** |
||||||
public ActivatableItem() { |
* |
||||||
super(); |
*/ |
||||||
} |
public ActivatableItem() { |
||||||
|
super(); |
||||||
/* (non-Javadoc) |
} |
||||||
* @see de.memtext.baseobjects.ActivatableItemI#isActive() |
|
||||||
*/ |
/* (non-Javadoc) |
||||||
public boolean isActive() { |
* @see de.memtext.baseobjects.ActivatableItemI#isActive() |
||||||
return isActive; |
*/ |
||||||
} |
@Override |
||||||
|
public boolean isActive() { |
||||||
/* (non-Javadoc) |
return isActive; |
||||||
* @see de.memtext.baseobjects.ActivatableItemI#setActive(boolean) |
} |
||||||
*/ |
|
||||||
public void setActive(boolean isActive) { |
/* (non-Javadoc) |
||||||
this.isActive=isActive; |
* @see de.memtext.baseobjects.ActivatableItemI#setActive(boolean) |
||||||
} |
*/ |
||||||
|
@Override |
||||||
} |
public void setActive(boolean isActive) { |
||||||
|
this.isActive = isActive; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|||||||
@ -1,10 +1,11 @@ |
|||||||
package de.memtext.baseobjects; |
package de.memtext.baseobjects; |
||||||
|
|
||||||
/** |
/** |
||||||
* |
* |
||||||
* @author MB |
* @author MB |
||||||
* */ |
* */ |
||||||
public interface ActivatableItemI { |
public interface ActivatableItemI { |
||||||
boolean isActive(); |
boolean isActive(); |
||||||
void setActive(boolean isActive); |
|
||||||
} |
void setActive(boolean isActive); |
||||||
|
} |
||||||
|
|||||||
@ -1,40 +1,39 @@ |
|||||||
package de.memtext.baseobjects; |
package de.memtext.baseobjects; |
||||||
|
|
||||||
public class ComparableObject extends NamedObject implements Comparable { |
public class ComparableObject extends NamedObject implements Comparable { |
||||||
private int sortNr; |
private int sortNr; |
||||||
private static final long serialVersionUID = 1; |
|
||||||
|
private static final long serialVersionUID = 1; |
||||||
public ComparableObject(String name, int sortNr) { |
|
||||||
super(name); |
public ComparableObject(String name, int sortNr) { |
||||||
this.sortNr = sortNr; |
super(name); |
||||||
} |
this.sortNr = sortNr; |
||||||
|
} |
||||||
public int compareTo(Object o) { |
|
||||||
int result = 0; |
@Override |
||||||
if (getSortNr() < ((ComparableObject) o).getSortNr()) |
public int compareTo(Object o) { |
||||||
result = -1; |
int result = 0; |
||||||
if (getSortNr() > ((ComparableObject) o).getSortNr()) |
if (getSortNr() < ((ComparableObject) o).getSortNr()) result = -1; |
||||||
result = 1; |
if (getSortNr() > ((ComparableObject) o).getSortNr()) result = 1; |
||||||
return result; |
return result; |
||||||
} |
} |
||||||
|
|
||||||
public int getSortNr() { |
public int getSortNr() { |
||||||
return sortNr; |
return sortNr; |
||||||
} |
} |
||||||
|
|
||||||
public boolean equals(Object o) { |
@Override |
||||||
boolean result = false; |
public boolean equals(Object o) { |
||||||
ComparableObject comp = (ComparableObject) o; |
boolean result = false; |
||||||
if (this.getName().equals(comp.getName()) |
ComparableObject comp = (ComparableObject) o; |
||||||
&& this.getSortNr() == comp.getSortNr()) |
if (this.getName().equals(comp.getName()) && this.getSortNr() == comp.getSortNr()) result = true; |
||||||
result = true; |
|
||||||
|
return result; |
||||||
return result; |
} |
||||||
} |
|
||||||
|
public void setSortNr(int sortNr) { |
||||||
public void setSortNr(int sortNr) { |
this.sortNr = sortNr; |
||||||
this.sortNr = sortNr; |
} |
||||||
} |
} |
||||||
} |
|
||||||
|
//Created on 22.10.2004 at 16:20:48
|
||||||
//Created on 22.10.2004 at 16:20:48
|
|
||||||
|
|||||||
@ -1,50 +1,52 @@ |
|||||||
package de.memtext.baseobjects; |
package de.memtext.baseobjects; |
||||||
|
|
||||||
import java.util.Collection; |
import java.util.Collection; |
||||||
import java.util.LinkedList; |
import java.util.LinkedList; |
||||||
|
|
||||||
/** |
/** |
||||||
* |
* |
||||||
* @author MB |
* @author MB |
||||||
* List with different behaviour when setting items, |
* List with different behaviour when setting items, |
||||||
* when index higher than count of elements doesn't throw |
* when index higher than count of elements doesn't throw |
||||||
* Exception, but adds as many nulls as necessary up to the |
* Exception, but adds as many nulls as necessary up to the |
||||||
* right count of elements and then sets the indicated position to |
* right count of elements and then sets the indicated position to |
||||||
* the new value |
* the new value |
||||||
* |
* |
||||||
* * If for example a value for column 5 is to be stored, but the data List only |
* * If for example a value for column 5 is to be stored, but the data List only |
||||||
* contains values for column 1 and 2, for column 3 and 4 null values are stored. |
* contains values for column 1 and 2, for column 3 and 4 null values are stored. |
||||||
|
|
||||||
* */ |
* */ |
||||||
public class DataList extends LinkedList { |
public class DataList extends LinkedList { |
||||||
private static final long serialVersionUID = 1; |
private static final long serialVersionUID = 1; |
||||||
|
|
||||||
/** |
/** |
||||||
* |
* |
||||||
*/ |
*/ |
||||||
public DataList() { |
public DataList() { |
||||||
super(); |
super(); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* @param c |
* @param c |
||||||
*/ |
*/ |
||||||
public DataList(Collection c) { |
public DataList(Collection c) { |
||||||
super(c); |
super(c); |
||||||
|
|
||||||
} |
} |
||||||
/** |
|
||||||
* If for example a value for column 5 is to be stored, but the data List only |
/** |
||||||
* contains values for column 1 and 2, for column 3 and 4 null values are stored. |
* If for example a value for column 5 is to be stored, but the data List only |
||||||
|
* contains values for column 1 and 2, for column 3 and 4 null values are stored. |
||||||
*/ |
|
||||||
public Object set(int index, Object o) { |
*/ |
||||||
while (index > this.size() - 1) { |
@Override |
||||||
this.add(null); |
public Object set(int index, Object o) { |
||||||
} |
while (index > this.size() - 1) { |
||||||
Object previous = this.get(index); |
this.add(null); |
||||||
super.set(index, o); |
} |
||||||
return previous; |
Object previous = this.get(index); |
||||||
} |
super.set(index, o); |
||||||
|
return previous; |
||||||
} |
} |
||||||
|
|
||||||
|
} |
||||||
|
|||||||
@ -1,18 +1,21 @@ |
|||||||
package de.memtext.baseobjects; |
package de.memtext.baseobjects; |
||||||
|
|
||||||
import java.awt.event.MouseAdapter; |
import java.awt.event.MouseAdapter; |
||||||
import java.awt.event.MouseEvent; |
import java.awt.event.MouseEvent; |
||||||
|
|
||||||
public abstract class DoubleClickMouseListener extends MouseAdapter { |
public abstract class DoubleClickMouseListener extends MouseAdapter { |
||||||
|
|
||||||
public DoubleClickMouseListener() { |
public DoubleClickMouseListener() { |
||||||
super(); |
super(); |
||||||
} |
} |
||||||
public final void mousePressed(MouseEvent e) { |
|
||||||
if (e.getClickCount() == 2) doubleClickOccured(); |
@Override |
||||||
} |
public final void mousePressed(MouseEvent e) { |
||||||
protected abstract void doubleClickOccured() ; |
if (e.getClickCount() == 2) doubleClickOccured(); |
||||||
|
} |
||||||
|
|
||||||
} |
protected abstract void doubleClickOccured(); |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
//Created on 16.03.2004 at 15:51:43
|
//Created on 16.03.2004 at 15:51:43
|
||||||
@ -1,50 +1,57 @@ |
|||||||
package de.memtext.baseobjects; |
package de.memtext.baseobjects; |
||||||
|
|
||||||
import java.io.Serializable; |
import java.io.Serializable; |
||||||
|
|
||||||
/** |
/** |
||||||
* |
* |
||||||
* @author MB |
* @author MB |
||||||
* */ |
* */ |
||||||
public class IdObject implements IdObjectI,Serializable { |
public class IdObject implements IdObjectI, Serializable { |
||||||
private Object id; |
private Object id; |
||||||
private static final long serialVersionUID = 1; |
|
||||||
public IdObject() { |
private static final long serialVersionUID = 1; |
||||||
|
|
||||||
} |
public IdObject() { |
||||||
public IdObject(Object id) { |
|
||||||
setId(id); |
} |
||||||
|
|
||||||
} |
public IdObject(Object id) { |
||||||
|
setId(id); |
||||||
/** |
|
||||||
* @return |
} |
||||||
*/ |
|
||||||
public Object getId() { |
/** |
||||||
return id; |
* @return |
||||||
} |
*/ |
||||||
|
@Override |
||||||
|
public Object getId() { |
||||||
|
return id; |
||||||
/** |
} |
||||||
* @param object |
|
||||||
*/ |
|
||||||
public void setId(Object object) { |
|
||||||
id = object; |
/** |
||||||
} |
* @param object |
||||||
|
*/ |
||||||
public String toString() |
@Override |
||||||
{ |
public void setId(Object object) { |
||||||
return "id:"+getId(); |
id = object; |
||||||
} |
} |
||||||
/** |
|
||||||
* Provides a deep copy |
@Override |
||||||
*/ |
public String toString() { |
||||||
public Object clone() throws CloneNotSupportedException { |
return "id:" + getId(); |
||||||
if (id!=null&&!(id instanceof String)&&!(id instanceof Integer)) |
} |
||||||
throw new CloneNotSupportedException(" You have to check in IdObject.clone if deep copying is necessary for class "+id.getClass()); |
|
||||||
|
/** |
||||||
IdObject cl=new IdObject(this.getId()); |
* Provides a deep copy |
||||||
return cl; |
*/ |
||||||
} |
@Override |
||||||
} |
public Object clone() throws CloneNotSupportedException { |
||||||
|
if (id != null && !(id instanceof String) && !(id instanceof Integer)) |
||||||
|
throw new CloneNotSupportedException(" You have to check in IdObject.clone if deep copying is necessary for class " + id.getClass()); |
||||||
|
|
||||||
|
IdObject cl = new IdObject(this.getId()); |
||||||
|
return cl; |
||||||
|
} |
||||||
|
} |
||||||
|
|||||||
@ -1,11 +1,13 @@ |
|||||||
package de.memtext.baseobjects; |
package de.memtext.baseobjects; |
||||||
/** |
|
||||||
* @see de.memtext.util.TreeUtils for a method creating key list (1,2,4) from nodes |
/** |
||||||
*/ |
* @see de.memtext.util.TreeUtils for a method creating key list (1,2,4) from nodes |
||||||
public interface IdObjectI { |
*/ |
||||||
public Object getId(); |
public interface IdObjectI { |
||||||
public void setId(Object id); |
public Object getId(); |
||||||
|
|
||||||
} |
public void setId(Object id); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
//Created on 30.01.2004 at 13:03:06
|
//Created on 30.01.2004 at 13:03:06
|
||||||
@ -1,28 +1,33 @@ |
|||||||
package de.memtext.baseobjects; |
package de.memtext.baseobjects; |
||||||
|
|
||||||
|
|
||||||
/** |
/** |
||||||
* For classes up in the hierarchy which need a name in some context |
* For classes up in the hierarchy which need a name in some context |
||||||
* but shouldn't pass it on to inheriting classes |
* but shouldn't pass it on to inheriting classes |
||||||
*/ |
*/ |
||||||
public final class NameDecorator implements NamedObjectI{ |
public final class NameDecorator implements NamedObjectI { |
||||||
private Object object; |
private Object object; |
||||||
private String name; |
|
||||||
public NameDecorator(String name,Object object) { |
private String name; |
||||||
this.name=name; |
|
||||||
this.object=object; |
public NameDecorator(String name, Object object) { |
||||||
} |
this.name = name; |
||||||
public String getName() { |
this.object = object; |
||||||
return name; |
} |
||||||
} |
|
||||||
public void setName(String name) { |
@Override |
||||||
this.name=name; |
public String getName() { |
||||||
} |
return name; |
||||||
|
} |
||||||
public Object getObject() |
|
||||||
{ |
@Override |
||||||
return object; |
public void setName(String name) { |
||||||
} |
this.name = name; |
||||||
} |
} |
||||||
|
|
||||||
|
public Object getObject() { |
||||||
|
return object; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
//Created on 25.11.2003 at 14:49:50
|
//Created on 25.11.2003 at 14:49:50
|
||||||
@ -1,83 +1,88 @@ |
|||||||
package de.memtext.baseobjects; |
package de.memtext.baseobjects; |
||||||
|
|
||||||
import java.io.Serializable; |
import java.io.Serializable; |
||||||
|
|
||||||
import de.memtext.util.EqualsUtil; |
import de.memtext.util.EqualsUtil; |
||||||
import de.memtext.util.HashCodeUtil; |
import de.memtext.util.HashCodeUtil; |
||||||
|
|
||||||
/** |
/** |
||||||
* |
* |
||||||
* @author MB |
* @author MB |
||||||
*/ |
*/ |
||||||
public class NamedIdObject extends NamedObject implements NamedIdObjectI, |
public class NamedIdObject extends NamedObject implements NamedIdObjectI, Serializable { |
||||||
Serializable { |
private Object id; |
||||||
private Object id; |
|
||||||
private static final long serialVersionUID = 1; |
private static final long serialVersionUID = 1; |
||||||
public NamedIdObject() { |
|
||||||
} |
public NamedIdObject() { |
||||||
|
} |
||||||
public NamedIdObject(NamedObjectI namedObject) { |
|
||||||
setName(namedObject.getName()); |
public NamedIdObject(NamedObjectI namedObject) { |
||||||
} |
setName(namedObject.getName()); |
||||||
|
} |
||||||
public NamedIdObject(Object id, String name) { |
|
||||||
setId(id); |
public NamedIdObject(Object id, String name) { |
||||||
setName(name); |
setId(id); |
||||||
} |
setName(name); |
||||||
|
} |
||||||
/** |
|
||||||
* @return |
/** |
||||||
*/ |
* @return |
||||||
public Object getId() { |
*/ |
||||||
return id; |
@Override |
||||||
} |
public Object getId() { |
||||||
|
return id; |
||||||
/** |
} |
||||||
* @param object |
|
||||||
*/ |
/** |
||||||
public void setId(Object id) { |
* @param object |
||||||
this.id = id; |
*/ |
||||||
} |
@Override |
||||||
|
public void setId(Object id) { |
||||||
public String toString() { |
this.id = id; |
||||||
return getId() + " - " + getName(); |
} |
||||||
} |
|
||||||
public boolean equals(Object o) |
@Override |
||||||
{ |
public String toString() { |
||||||
boolean result=false; |
return getId() + " - " + getName(); |
||||||
if (o instanceof NamedIdObject) |
} |
||||||
{ |
|
||||||
NamedIdObject o2=(NamedIdObject)o; |
@Override |
||||||
result=EqualsUtil.areEqual(this.getId(),o2.getId())&&EqualsUtil.areEqual(this.getName(),o2.getName()); |
public boolean equals(Object o) { |
||||||
|
boolean result = false; |
||||||
|
if (o instanceof NamedIdObject) { |
||||||
} |
NamedIdObject o2 = (NamedIdObject) o; |
||||||
return result; |
result = EqualsUtil.areEqual(this.getId(), o2.getId()) && EqualsUtil.areEqual(this.getName(), o2.getName()); |
||||||
} |
|
||||||
public int hashCode(){ |
|
||||||
int result = HashCodeUtil.SEED; |
} |
||||||
//collect the contributions of various fields
|
return result; |
||||||
result = HashCodeUtil.hash(result, getId()); |
} |
||||||
result = HashCodeUtil.hash(result, getName()); |
|
||||||
|
@Override |
||||||
return result; |
public int hashCode() { |
||||||
} |
int result = HashCodeUtil.SEED; |
||||||
/** |
//collect the contributions of various fields
|
||||||
* Provides a deep copy |
result = HashCodeUtil.hash(result, getId()); |
||||||
*/ |
result = HashCodeUtil.hash(result, getName()); |
||||||
public Object clone() throws CloneNotSupportedException { |
|
||||||
|
return result; |
||||||
NamedIdObject cl = new NamedIdObject((NamedObject) super.clone()); |
} |
||||||
|
|
||||||
if (id != null && !(id instanceof String) && !(id instanceof Integer)) |
/** |
||||||
throw new CloneNotSupportedException( |
* Provides a deep copy |
||||||
" You have to check in NamedIdObject.clone if deep copying is necessary for class " |
*/ |
||||||
+ id.getClass()); |
@Override |
||||||
|
public Object clone() throws CloneNotSupportedException { |
||||||
if (this.id != null) |
|
||||||
cl.setId(id); |
NamedIdObject cl = new NamedIdObject((NamedObject) super.clone()); |
||||||
return cl; |
|
||||||
} |
if (id != null && !(id instanceof String) && !(id instanceof Integer)) |
||||||
|
throw new CloneNotSupportedException(" You have to check in NamedIdObject.clone if deep copying is necessary for class " + id.getClass()); |
||||||
|
|
||||||
|
if (this.id != null) cl.setId(id); |
||||||
|
return cl; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
} |
} |
||||||
@ -1,10 +1,10 @@ |
|||||||
package de.memtext.baseobjects; |
package de.memtext.baseobjects; |
||||||
|
|
||||||
/** |
/** |
||||||
* |
* |
||||||
* @author MB |
* @author MB |
||||||
* */ |
* */ |
||||||
public interface NamedIdObjectI extends NamedObjectI, IdObjectI{ |
public interface NamedIdObjectI extends NamedObjectI, IdObjectI { |
||||||
|
|
||||||
|
|
||||||
} |
} |
||||||
@ -1,91 +1,88 @@ |
|||||||
package de.memtext.baseobjects; |
package de.memtext.baseobjects; |
||||||
|
|
||||||
import java.io.Serializable; |
import java.io.Serializable; |
||||||
|
|
||||||
import de.memtext.tree.KeyParentEqualException; |
import de.memtext.tree.KeyParentEqualException; |
||||||
import de.memtext.util.EqualsUtil; |
import de.memtext.util.EqualsUtil; |
||||||
import de.memtext.util.HashCodeUtil; |
import de.memtext.util.HashCodeUtil; |
||||||
|
|
||||||
public class NamedIdObjectWithParent extends NamedIdObject implements |
public class NamedIdObjectWithParent extends NamedIdObject implements NamedIdObjectWithParentI, Serializable { |
||||||
NamedIdObjectWithParentI, Serializable { |
private Object parentKey; |
||||||
private Object parentKey; |
|
||||||
private static final long serialVersionUID = 1; |
private static final long serialVersionUID = 1; |
||||||
public NamedIdObjectWithParent() { |
|
||||||
super(); |
public NamedIdObjectWithParent() { |
||||||
} |
super(); |
||||||
|
} |
||||||
public NamedIdObjectWithParent(NamedIdObjectI namedIdObject) { |
|
||||||
setId(namedIdObject.getId()); |
public NamedIdObjectWithParent(NamedIdObjectI namedIdObject) { |
||||||
setName(namedIdObject.getName()); |
setId(namedIdObject.getId()); |
||||||
} |
setName(namedIdObject.getName()); |
||||||
|
} |
||||||
public NamedIdObjectWithParent(Object id, String name) { |
|
||||||
super(id, name); |
public NamedIdObjectWithParent(Object id, String name) { |
||||||
} |
super(id, name); |
||||||
|
} |
||||||
public NamedIdObjectWithParent(Object id, String name, Object parentKey) |
|
||||||
throws KeyParentEqualException { |
public NamedIdObjectWithParent(Object id, String name, Object parentKey) throws KeyParentEqualException { |
||||||
super(id, name); |
super(id, name); |
||||||
setParentKey(parentKey); |
setParentKey(parentKey); |
||||||
} |
} |
||||||
|
|
||||||
public Object getParentKey() { |
@Override |
||||||
return parentKey; |
public Object getParentKey() { |
||||||
} |
return parentKey; |
||||||
|
} |
||||||
public void setParentKey(Object parentKey) throws KeyParentEqualException { |
|
||||||
this.parentKey = parentKey; |
@Override |
||||||
if ((getId() == null && getParentKey() == null) |
public void setParentKey(Object parentKey) throws KeyParentEqualException { |
||||||
|| (getId() != null && getId().equals(getParentKey()))) |
this.parentKey = parentKey; |
||||||
throw new KeyParentEqualException((NamedIdObjectWithParentI) this); |
if ((getId() == null && getParentKey() == null) || (getId() != null && getId().equals(getParentKey()))) throw new KeyParentEqualException((NamedIdObjectWithParentI) this); |
||||||
} |
} |
||||||
//TODO aufteilen auf übergeordnete Objekte
|
|
||||||
public boolean equals(Object obj) { |
//TODO aufteilen auf übergeordnete Objekte
|
||||||
|
@Override |
||||||
if ( this == obj ) return true; |
public boolean equals(Object obj) { |
||||||
if ( obj == null || obj.getClass() != this.getClass() ) return false; |
|
||||||
|
if (this == obj) return true; |
||||||
NamedIdObjectWithParent i2=(NamedIdObjectWithParent)obj; |
if (obj == null || obj.getClass() != this.getClass()) return false; |
||||||
return |
|
||||||
EqualsUtil.areEqual(this.getId(), i2.getId()) && |
NamedIdObjectWithParent i2 = (NamedIdObjectWithParent) obj; |
||||||
EqualsUtil.areEqual(this.getName(), i2.getName()) && |
return EqualsUtil.areEqual(this.getId(), i2.getId()) && EqualsUtil.areEqual(this.getName(), i2.getName()) && EqualsUtil.areEqual(this.getParentKey(), i2.getParentKey()); |
||||||
EqualsUtil.areEqual(this.getParentKey(), i2.getParentKey()); |
|
||||||
|
|
||||||
|
} |
||||||
} |
|
||||||
|
/* |
||||||
/* |
* @see java.lang.Object#hashCode() |
||||||
* @see java.lang.Object#hashCode() |
*/ |
||||||
*/ |
@Override |
||||||
public int hashCode() { |
public int hashCode() { |
||||||
int result = HashCodeUtil.SEED; |
int result = HashCodeUtil.SEED; |
||||||
result = HashCodeUtil.hash(result, getId()); |
result = HashCodeUtil.hash(result, getId()); |
||||||
result = HashCodeUtil.hash(result, getName()); |
result = HashCodeUtil.hash(result, getName()); |
||||||
result = HashCodeUtil.hash(result, getParentKey()); |
result = HashCodeUtil.hash(result, getParentKey()); |
||||||
return result ; |
return result; |
||||||
} |
} |
||||||
/** |
|
||||||
* Provides a deep copy |
/** |
||||||
*/ |
* Provides a deep copy |
||||||
public Object clone() throws CloneNotSupportedException { |
*/ |
||||||
|
@Override |
||||||
NamedIdObjectWithParent cl = new NamedIdObjectWithParent( |
public Object clone() throws CloneNotSupportedException { |
||||||
(NamedIdObject) super.clone()); |
|
||||||
|
NamedIdObjectWithParent cl = new NamedIdObjectWithParent((NamedIdObject) super.clone()); |
||||||
if (parentKey != null && !(parentKey instanceof String) |
|
||||||
&& !(parentKey instanceof Integer)) |
if (parentKey != null && !(parentKey instanceof String) && !(parentKey instanceof Integer)) |
||||||
throw new CloneNotSupportedException( |
throw new CloneNotSupportedException(" You have to check in NamedIdObjectWithParent.clone if deep copying is necessary for class " + parentKey.getClass()); |
||||||
" You have to check in NamedIdObjectWithParent.clone if deep copying is necessary for class " |
|
||||||
+ parentKey.getClass()); |
if (this.parentKey != null) try { |
||||||
|
cl.setParentKey(this.parentKey); |
||||||
if (this.parentKey != null) |
} catch (KeyParentEqualException e) { |
||||||
try { |
throw new CloneNotSupportedException("Cloning didn't work" + e); |
||||||
cl.setParentKey(this.parentKey); |
} |
||||||
} catch (KeyParentEqualException e) { |
return cl; |
||||||
throw new CloneNotSupportedException("Cloning didn't work" + e); |
} |
||||||
} |
} |
||||||
return cl; |
|
||||||
} |
//Created on 18.11.2003
|
||||||
} |
|
||||||
|
|
||||||
//Created on 18.11.2003
|
|
||||||
|
|||||||
@ -1,9 +1,10 @@ |
|||||||
package de.memtext.baseobjects; |
package de.memtext.baseobjects; |
||||||
|
|
||||||
import de.memtext.tree.KeyParentEqualException; |
import de.memtext.tree.KeyParentEqualException; |
||||||
|
|
||||||
public interface NamedIdObjectWithParentI extends NamedIdObjectI { |
public interface NamedIdObjectWithParentI extends NamedIdObjectI { |
||||||
public Object getParentKey(); |
public Object getParentKey(); |
||||||
public void setParentKey(Object parentKey) throws KeyParentEqualException; |
|
||||||
} |
public void setParentKey(Object parentKey) throws KeyParentEqualException; |
||||||
|
} |
||||||
//Created on 18.11.2003
|
//Created on 18.11.2003
|
||||||
@ -1,49 +1,57 @@ |
|||||||
package de.memtext.baseobjects; |
package de.memtext.baseobjects; |
||||||
|
|
||||||
import java.io.Serializable; |
import java.io.Serializable; |
||||||
|
|
||||||
/** |
/** |
||||||
* |
* |
||||||
* @author MB |
* @author MB |
||||||
* */ |
* */ |
||||||
public class NamedObject implements NamedObjectI,Serializable { |
public class NamedObject implements NamedObjectI, Serializable { |
||||||
private String name; |
private String name; |
||||||
private static final long serialVersionUID = 1; |
|
||||||
/** |
private static final long serialVersionUID = 1; |
||||||
* |
|
||||||
*/ |
/** |
||||||
|
* |
||||||
public NamedObject() { |
*/ |
||||||
|
|
||||||
} |
public NamedObject() { |
||||||
public NamedObject(String name) { |
|
||||||
setName(name); |
} |
||||||
} |
|
||||||
|
public NamedObject(String name) { |
||||||
|
setName(name); |
||||||
/** |
} |
||||||
* @return |
|
||||||
*/ |
|
||||||
public String getName() { |
/** |
||||||
return name; |
* @return |
||||||
} |
*/ |
||||||
|
@Override |
||||||
|
public String getName() { |
||||||
|
return name; |
||||||
/** |
} |
||||||
* @param string |
|
||||||
*/ |
|
||||||
public void setName(String string) { |
|
||||||
name = string; |
/** |
||||||
} |
* @param string |
||||||
public String toString() { |
*/ |
||||||
return name; |
@Override |
||||||
} |
public void setName(String string) { |
||||||
|
name = string; |
||||||
/** |
} |
||||||
* Provides a deep copy |
|
||||||
*/ |
@Override |
||||||
protected Object clone() throws CloneNotSupportedException { |
public String toString() { |
||||||
return new NamedObject(this.getName()); |
return name; |
||||||
} |
} |
||||||
} |
|
||||||
|
/** |
||||||
|
* Provides a deep copy |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
protected Object clone() throws CloneNotSupportedException { |
||||||
|
return new NamedObject(this.getName()); |
||||||
|
} |
||||||
|
} |
||||||
|
|||||||
@ -1,13 +1,15 @@ |
|||||||
package de.memtext.baseobjects; |
package de.memtext.baseobjects; |
||||||
|
|
||||||
/** |
/** |
||||||
* |
* |
||||||
* @author MB |
* @author MB |
||||||
* */ |
* */ |
||||||
public interface NamedObjectI { |
public interface NamedObjectI { |
||||||
|
|
||||||
public String getName(); |
public String getName(); |
||||||
|
|
||||||
public void setName(String name); |
public void setName(String name); |
||||||
public String toString(); |
|
||||||
|
@Override |
||||||
|
public String toString(); |
||||||
} |
} |
||||||
@ -1,32 +1,34 @@ |
|||||||
package de.memtext.baseobjects; |
package de.memtext.baseobjects; |
||||||
/** |
|
||||||
* This class holds information about a string that is to be |
/** |
||||||
* searched for and another string that the former is to be |
* This class holds information about a string that is to be |
||||||
* replaced with. |
* searched for and another string that the former is to be |
||||||
* By default both are empty strings. |
* replaced with. |
||||||
*/ |
* By default both are empty strings. |
||||||
public class SearchReplaceTextHolder { |
*/ |
||||||
private String searchText="", replaceText=""; |
public class SearchReplaceTextHolder { |
||||||
public SearchReplaceTextHolder() { |
private String searchText = "", replaceText = ""; |
||||||
super(); |
|
||||||
} |
public SearchReplaceTextHolder() { |
||||||
|
super(); |
||||||
public String getReplaceText() { |
} |
||||||
return replaceText; |
|
||||||
} |
public String getReplaceText() { |
||||||
|
return replaceText; |
||||||
public String getSearchText() { |
} |
||||||
return searchText; |
|
||||||
} |
public String getSearchText() { |
||||||
|
return searchText; |
||||||
public void setReplaceText(String string) { |
} |
||||||
replaceText = string; |
|
||||||
} |
public void setReplaceText(String string) { |
||||||
|
replaceText = string; |
||||||
public void setSearchText(String string) { |
} |
||||||
searchText = string; |
|
||||||
} |
public void setSearchText(String string) { |
||||||
|
searchText = string; |
||||||
} |
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
//Created on 04.02.2004 at 11:40:47
|
//Created on 04.02.2004 at 11:40:47
|
||||||
@ -1,86 +1,98 @@ |
|||||||
package de.memtext.baseobjects; |
package de.memtext.baseobjects; |
||||||
|
|
||||||
import java.io.Serializable; |
import java.io.Serializable; |
||||||
import java.util.ArrayList; |
import java.util.ArrayList; |
||||||
import java.util.Iterator; |
import java.util.Iterator; |
||||||
import java.util.List; |
import java.util.List; |
||||||
|
|
||||||
import de.memtext.rights.Rights; |
import de.memtext.rights.Rights; |
||||||
|
|
||||||
/** |
/** |
||||||
* stellt einen User dar, könnte sicherer gemacht werden mit |
* stellt einen User dar, könnte sicherer gemacht werden mit |
||||||
* defensive Copying |
* defensive Copying |
||||||
* @author MB |
* @author MB |
||||||
* */ |
* */ |
||||||
public class User extends NamedIdObject implements Serializable { |
public class User extends NamedIdObject implements Serializable { |
||||||
private List groupMembershipIds = new ArrayList(5); |
private List groupMembershipIds = new ArrayList(5); |
||||||
private String passwd; |
|
||||||
|
private String passwd; |
||||||
private Rights rights; |
|
||||||
private boolean isAdmin=false; |
private Rights rights; |
||||||
private static final long serialVersionUID = 1; |
|
||||||
public User() { |
private boolean isAdmin = false; |
||||||
setName(""); |
|
||||||
setPasswd(""); |
private static final long serialVersionUID = 1; |
||||||
} |
|
||||||
public User(String username, String passwd) { |
public User() { |
||||||
setName(username); |
setName(""); |
||||||
setPasswd(passwd); |
setPasswd(""); |
||||||
|
} |
||||||
} |
|
||||||
|
public User(String username, String passwd) { |
||||||
public User(String username, Integer userid) { |
setName(username); |
||||||
super(userid,username); |
setPasswd(passwd); |
||||||
if (userid == null) |
|
||||||
throw new IllegalArgumentException("No user without userid allowed"); |
} |
||||||
} |
|
||||||
public User(String username) { |
public User(String username, Integer userid) { |
||||||
setName(username); |
super(userid, username); |
||||||
} |
if (userid == null) throw new IllegalArgumentException("No user without userid allowed"); |
||||||
/** |
} |
||||||
* @param groupmemberships |
|
||||||
*/ |
public User(String username) { |
||||||
public void addAllGroupmembershipsById(List groupmemberships) { |
setName(username); |
||||||
groupMembershipIds.addAll(groupmemberships); |
} |
||||||
} |
|
||||||
public void addGroupMembershipById(Integer groupid) { |
/** |
||||||
groupMembershipIds.add(groupid); |
* @param groupmemberships |
||||||
} |
*/ |
||||||
|
public void addAllGroupmembershipsById(List groupmemberships) { |
||||||
public String getPasswd() { |
groupMembershipIds.addAll(groupmemberships); |
||||||
return passwd; |
} |
||||||
} |
|
||||||
|
public void addGroupMembershipById(Integer groupid) { |
||||||
|
groupMembershipIds.add(groupid); |
||||||
|
} |
||||||
public Iterator groupmembershipIdIterator() { |
|
||||||
return groupMembershipIds.iterator(); |
public String getPasswd() { |
||||||
} |
return passwd; |
||||||
public void removeGroupMembershipById(Integer groupid) { |
} |
||||||
groupMembershipIds.remove(groupid); |
|
||||||
} |
|
||||||
|
|
||||||
public void setPasswd(String pwd) { |
public Iterator groupmembershipIdIterator() { |
||||||
passwd = pwd; |
return groupMembershipIds.iterator(); |
||||||
} |
} |
||||||
|
|
||||||
|
public void removeGroupMembershipById(Integer groupid) { |
||||||
public String toString() |
groupMembershipIds.remove(groupid); |
||||||
{ |
} |
||||||
|
|
||||||
return getName(); |
public void setPasswd(String pwd) { |
||||||
} |
passwd = pwd; |
||||||
public Rights getRights() { |
} |
||||||
return rights; |
|
||||||
} |
|
||||||
public void setRights(Rights rights) { |
@Override |
||||||
this.rights = rights; |
public String toString() { |
||||||
} |
|
||||||
public boolean isAdmin() { |
return getName(); |
||||||
return isAdmin; |
} |
||||||
} |
|
||||||
public void setAdmin(boolean isAdmin) { |
public Rights getRights() { |
||||||
this.isAdmin = isAdmin; |
return rights; |
||||||
} |
} |
||||||
|
|
||||||
} |
public void setRights(Rights rights) { |
||||||
|
this.rights = rights; |
||||||
|
} |
||||||
|
|
||||||
|
public boolean isAdmin() { |
||||||
|
return isAdmin; |
||||||
|
} |
||||||
|
|
||||||
|
public void setAdmin(boolean isAdmin) { |
||||||
|
this.isAdmin = isAdmin; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|||||||
@ -1,321 +1,347 @@ |
|||||||
package de.memtext.baseobjects.coll; |
package de.memtext.baseobjects.coll; |
||||||
|
|
||||||
import java.io.Serializable; |
import java.io.Serializable; |
||||||
import java.util.Collection; |
import java.util.Collection; |
||||||
import java.util.Iterator; |
import java.util.Iterator; |
||||||
import java.util.LinkedList; |
import java.util.LinkedList; |
||||||
import java.util.List; |
import java.util.List; |
||||||
import java.util.ListIterator; |
import java.util.ListIterator; |
||||||
|
|
||||||
import de.memtext.baseobjects.ActivatableItemI; |
import de.memtext.baseobjects.ActivatableItemI; |
||||||
|
|
||||||
/** |
/** |
||||||
* |
* |
||||||
* @author MB |
* @author MB |
||||||
* */ |
* */ |
||||||
public class ActivatableItemList implements List,Serializable { |
public class ActivatableItemList implements List, Serializable { |
||||||
private List collect = new LinkedList(); |
private List collect = new LinkedList(); |
||||||
private static final long serialVersionUID = 1; |
|
||||||
/** |
private static final long serialVersionUID = 1; |
||||||
* |
|
||||||
*/ |
/** |
||||||
public ActivatableItemList() { |
* |
||||||
super(); |
*/ |
||||||
} |
public ActivatableItemList() { |
||||||
|
super(); |
||||||
public Iterator activeItemIterator() { |
} |
||||||
return getActiveItems().iterator(); |
|
||||||
} |
public Iterator activeItemIterator() { |
||||||
|
return getActiveItems().iterator(); |
||||||
public Collection getActiveItems() { |
} |
||||||
Collection result = new LinkedList(); |
|
||||||
for (Iterator iter = this.iterator(); iter.hasNext();) { |
public Collection getActiveItems() { |
||||||
ActivatableItemI element = (ActivatableItemI) iter.next(); |
Collection result = new LinkedList(); |
||||||
if (element.isActive()) |
for (Iterator iter = this.iterator(); iter.hasNext();) { |
||||||
result.add(element); |
ActivatableItemI element = (ActivatableItemI) iter.next(); |
||||||
} |
if (element.isActive()) result.add(element); |
||||||
return result; |
} |
||||||
} |
return result; |
||||||
public void setAllActive(boolean active) { |
} |
||||||
for (Iterator iter = this.iterator(); iter.hasNext();) { |
|
||||||
ActivatableItemI element = (ActivatableItemI) iter.next(); |
public void setAllActive(boolean active) { |
||||||
element.setActive(active); |
for (Iterator iter = this.iterator(); iter.hasNext();) { |
||||||
} |
ActivatableItemI element = (ActivatableItemI) iter.next(); |
||||||
} |
element.setActive(active); |
||||||
public boolean isAllActive() { |
} |
||||||
boolean result = true; |
} |
||||||
for (Iterator iter = this.iterator(); iter.hasNext();) { |
|
||||||
ActivatableItemI element = (ActivatableItemI) iter.next(); |
public boolean isAllActive() { |
||||||
if (!element.isActive()) { |
boolean result = true; |
||||||
result = false; |
for (Iterator iter = this.iterator(); iter.hasNext();) { |
||||||
break; |
ActivatableItemI element = (ActivatableItemI) iter.next(); |
||||||
} |
if (!element.isActive()) { |
||||||
} |
result = false; |
||||||
return result; |
break; |
||||||
} |
} |
||||||
public boolean isAllDeactivated() { |
} |
||||||
boolean result = true; |
return result; |
||||||
for (Iterator iter = this.iterator(); iter.hasNext();) { |
} |
||||||
ActivatableItemI element = (ActivatableItemI) iter.next(); |
|
||||||
if (element.isActive()) { |
public boolean isAllDeactivated() { |
||||||
result = false; |
boolean result = true; |
||||||
break; |
for (Iterator iter = this.iterator(); iter.hasNext();) { |
||||||
} |
ActivatableItemI element = (ActivatableItemI) iter.next(); |
||||||
} |
if (element.isActive()) { |
||||||
return result; |
result = false; |
||||||
} |
break; |
||||||
public int activeCount() { |
} |
||||||
int count = 0; |
} |
||||||
for (Iterator iter = this.iterator(); iter.hasNext();) { |
return result; |
||||||
ActivatableItemI element = (ActivatableItemI) iter.next(); |
} |
||||||
if (element.isActive()) |
|
||||||
count++; |
public int activeCount() { |
||||||
} |
int count = 0; |
||||||
return count; |
for (Iterator iter = this.iterator(); iter.hasNext();) { |
||||||
} |
ActivatableItemI element = (ActivatableItemI) iter.next(); |
||||||
public int deactivatedCount() { |
if (element.isActive()) count++; |
||||||
|
} |
||||||
int count = 0; |
return count; |
||||||
for (Iterator iter = this.iterator(); iter.hasNext();) { |
} |
||||||
ActivatableItemI element = (ActivatableItemI) iter.next(); |
|
||||||
if (!element.isActive()) |
public int deactivatedCount() { |
||||||
count++; |
|
||||||
} |
int count = 0; |
||||||
return count; |
for (Iterator iter = this.iterator(); iter.hasNext();) { |
||||||
|
ActivatableItemI element = (ActivatableItemI) iter.next(); |
||||||
} |
if (!element.isActive()) count++; |
||||||
public ActivatableItemI getActiveItem(int pos) { |
} |
||||||
ActivatableItemI result = null; |
return count; |
||||||
int i = 0; |
|
||||||
|
} |
||||||
for (Iterator it = activeItemIterator(); it.hasNext();) { |
|
||||||
ActivatableItemI element = (ActivatableItemI) it.next(); |
public ActivatableItemI getActiveItem(int pos) { |
||||||
if (i == pos) { |
ActivatableItemI result = null; |
||||||
result = element; |
int i = 0; |
||||||
break; |
|
||||||
} |
for (Iterator it = activeItemIterator(); it.hasNext();) { |
||||||
i++; |
ActivatableItemI element = (ActivatableItemI) it.next(); |
||||||
} |
if (i == pos) { |
||||||
if (result == null) |
result = element; |
||||||
throw new RuntimeException("not found"); |
break; |
||||||
|
} |
||||||
return result; |
i++; |
||||||
} |
} |
||||||
/** |
if (result == null) throw new RuntimeException("not found"); |
||||||
* |
|
||||||
* @return null if all deactivated |
return result; |
||||||
*/ |
} |
||||||
public ActivatableItemI getFirstActive() { |
|
||||||
ActivatableItemI result = null; |
/** |
||||||
for (Iterator iter = this.iterator(); iter.hasNext();) { |
* |
||||||
ActivatableItemI element = (ActivatableItemI) iter.next(); |
* @return null if all deactivated |
||||||
if (element.isActive()) { |
*/ |
||||||
result = element; |
public ActivatableItemI getFirstActive() { |
||||||
break; |
ActivatableItemI result = null; |
||||||
} |
for (Iterator iter = this.iterator(); iter.hasNext();) { |
||||||
} |
ActivatableItemI element = (ActivatableItemI) iter.next(); |
||||||
return result; |
if (element.isActive()) { |
||||||
} |
result = element; |
||||||
/** |
break; |
||||||
* |
} |
||||||
* @return null if all active |
} |
||||||
*/ |
return result; |
||||||
public ActivatableItemI getFirstDeactivated() { |
} |
||||||
ActivatableItemI result = null; |
|
||||||
for (Iterator iter = this.iterator(); iter.hasNext();) { |
/** |
||||||
ActivatableItemI element = (ActivatableItemI) iter.next(); |
* |
||||||
if (!element.isActive()) { |
* @return null if all active |
||||||
result = element; |
*/ |
||||||
break; |
public ActivatableItemI getFirstDeactivated() { |
||||||
} |
ActivatableItemI result = null; |
||||||
} |
for (Iterator iter = this.iterator(); iter.hasNext();) { |
||||||
return result; |
ActivatableItemI element = (ActivatableItemI) iter.next(); |
||||||
} |
if (!element.isActive()) { |
||||||
/* (non-Javadoc) |
result = element; |
||||||
* @see java.util.Collection#size() |
break; |
||||||
*/ |
} |
||||||
public int size() { |
} |
||||||
return collect.size(); |
return result; |
||||||
} |
} |
||||||
|
|
||||||
/* (non-Javadoc) |
/* (non-Javadoc) |
||||||
* @see java.util.Collection#isEmpty() |
* @see java.util.Collection#size() |
||||||
*/ |
*/ |
||||||
public boolean isEmpty() { |
@Override |
||||||
return collect.isEmpty(); |
public int size() { |
||||||
} |
return collect.size(); |
||||||
|
} |
||||||
/* (non-Javadoc) |
|
||||||
* @see java.util.Collection#contains(java.lang.Object) |
/* (non-Javadoc) |
||||||
*/ |
* @see java.util.Collection#isEmpty() |
||||||
public boolean contains(Object o) { |
*/ |
||||||
return collect.contains(o); |
@Override |
||||||
} |
public boolean isEmpty() { |
||||||
|
return collect.isEmpty(); |
||||||
/* (non-Javadoc) |
} |
||||||
* @see java.util.Collection#iterator() |
|
||||||
*/ |
/* (non-Javadoc) |
||||||
public Iterator iterator() { |
* @see java.util.Collection#contains(java.lang.Object) |
||||||
return collect.iterator(); |
*/ |
||||||
} |
@Override |
||||||
|
public boolean contains(Object o) { |
||||||
/* (non-Javadoc) |
return collect.contains(o); |
||||||
* @see java.util.Collection#toArray() |
} |
||||||
*/ |
|
||||||
public Object[] toArray() { |
/* (non-Javadoc) |
||||||
return collect.toArray(); |
* @see java.util.Collection#iterator() |
||||||
} |
*/ |
||||||
|
@Override |
||||||
/* (non-Javadoc) |
public Iterator iterator() { |
||||||
* @see java.util.Collection#toArray(java.lang.Object[]) |
return collect.iterator(); |
||||||
*/ |
} |
||||||
public Object[] toArray(Object[] a) { |
|
||||||
return collect.toArray(a); |
/* (non-Javadoc) |
||||||
} |
* @see java.util.Collection#toArray() |
||||||
|
*/ |
||||||
/* (non-Javadoc) |
@Override |
||||||
* @see java.util.Collection#containsAll(java.util.Collection) |
public Object[] toArray() { |
||||||
*/ |
return collect.toArray(); |
||||||
public boolean containsAll(Collection c) { |
} |
||||||
return collect.containsAll(c); |
|
||||||
} |
/* (non-Javadoc) |
||||||
|
* @see java.util.Collection#toArray(java.lang.Object[]) |
||||||
/* (non-Javadoc) |
*/ |
||||||
* @see java.util.Collection#addAll(java.util.Collection) |
@Override |
||||||
*/ |
public Object[] toArray(Object[] a) { |
||||||
public boolean addAll(Collection c) { |
return collect.toArray(a); |
||||||
for (Iterator iter = c.iterator(); iter.hasNext();) { |
} |
||||||
Object element = iter.next(); |
|
||||||
if (!(element instanceof ActivatableItemI)) |
/* (non-Javadoc) |
||||||
throw new IllegalArgumentException("only Activatable items"); |
* @see java.util.Collection#containsAll(java.util.Collection) |
||||||
|
*/ |
||||||
} |
@Override |
||||||
return collect.addAll(c); |
public boolean containsAll(Collection c) { |
||||||
} |
return collect.containsAll(c); |
||||||
|
} |
||||||
/* (non-Javadoc) |
|
||||||
* @see java.util.Collection#removeAll(java.util.Collection) |
/* (non-Javadoc) |
||||||
*/ |
* @see java.util.Collection#addAll(java.util.Collection) |
||||||
public boolean removeAll(Collection c) { |
*/ |
||||||
return collect.removeAll(c); |
@Override |
||||||
} |
public boolean addAll(Collection c) { |
||||||
|
for (Iterator iter = c.iterator(); iter.hasNext();) { |
||||||
/* (non-Javadoc) |
Object element = iter.next(); |
||||||
* @see java.util.Collection#retainAll(java.util.Collection) |
if (!(element instanceof ActivatableItemI)) throw new IllegalArgumentException("only Activatable items"); |
||||||
*/ |
|
||||||
public boolean retainAll(Collection c) { |
} |
||||||
for (Iterator iter = c.iterator(); iter.hasNext();) { |
return collect.addAll(c); |
||||||
Object element = iter.next(); |
} |
||||||
if (!(element instanceof ActivatableItemI)) |
|
||||||
throw new IllegalArgumentException("only Activatable items"); |
/* (non-Javadoc) |
||||||
|
* @see java.util.Collection#removeAll(java.util.Collection) |
||||||
} |
*/ |
||||||
return collect.retainAll(c); |
@Override |
||||||
} |
public boolean removeAll(Collection c) { |
||||||
|
return collect.removeAll(c); |
||||||
/* (non-Javadoc) |
} |
||||||
* @see java.util.Collection#clear() |
|
||||||
*/ |
/* (non-Javadoc) |
||||||
public void clear() { |
* @see java.util.Collection#retainAll(java.util.Collection) |
||||||
collect.clear(); |
*/ |
||||||
} |
@Override |
||||||
|
public boolean retainAll(Collection c) { |
||||||
/* (non-Javadoc) |
for (Iterator iter = c.iterator(); iter.hasNext();) { |
||||||
* @see java.util.Collection#add(java.lang.Object) |
Object element = iter.next(); |
||||||
*/ |
if (!(element instanceof ActivatableItemI)) throw new IllegalArgumentException("only Activatable items"); |
||||||
public boolean add(Object o) { |
|
||||||
if (!(o instanceof ActivatableItemI)) |
} |
||||||
throw new IllegalArgumentException("only Activatable items"); |
return collect.retainAll(c); |
||||||
return collect.add(o); |
} |
||||||
} |
|
||||||
|
/* (non-Javadoc) |
||||||
/* (non-Javadoc) |
* @see java.util.Collection#clear() |
||||||
* @see java.util.Collection#remove(java.lang.Object) |
*/ |
||||||
*/ |
@Override |
||||||
public boolean remove(Object o) { |
public void clear() { |
||||||
return collect.remove(o); |
collect.clear(); |
||||||
} |
} |
||||||
|
|
||||||
/* (non-Javadoc) |
/* (non-Javadoc) |
||||||
* @see java.util.List#addAll(int, java.util.Collection) |
* @see java.util.Collection#add(java.lang.Object) |
||||||
*/ |
*/ |
||||||
public boolean addAll(int index, Collection c) { |
@Override |
||||||
for (Iterator iter = c.iterator(); iter.hasNext();) { |
public boolean add(Object o) { |
||||||
Object element = iter.next(); |
if (!(o instanceof ActivatableItemI)) throw new IllegalArgumentException("only Activatable items"); |
||||||
if (!(element instanceof ActivatableItemI)) |
return collect.add(o); |
||||||
throw new IllegalArgumentException("only Activatable items"); |
} |
||||||
|
|
||||||
} |
/* (non-Javadoc) |
||||||
return collect.addAll(c); |
* @see java.util.Collection#remove(java.lang.Object) |
||||||
} |
*/ |
||||||
|
@Override |
||||||
/* (non-Javadoc) |
public boolean remove(Object o) { |
||||||
* @see java.util.List#get(int) |
return collect.remove(o); |
||||||
*/ |
} |
||||||
public Object get(int index) { |
|
||||||
return collect.get(index); |
/* (non-Javadoc) |
||||||
} |
* @see java.util.List#addAll(int, java.util.Collection) |
||||||
|
*/ |
||||||
/* (non-Javadoc) |
@Override |
||||||
* @see java.util.List#set(int, java.lang.Object) |
public boolean addAll(int index, Collection c) { |
||||||
*/ |
for (Iterator iter = c.iterator(); iter.hasNext();) { |
||||||
public Object set(int index, Object element) { |
Object element = iter.next(); |
||||||
if (!(element instanceof ActivatableItemI)) |
if (!(element instanceof ActivatableItemI)) throw new IllegalArgumentException("only Activatable items"); |
||||||
throw new IllegalArgumentException("only Activatable items"); |
|
||||||
return collect.set(index, element); |
} |
||||||
} |
return collect.addAll(c); |
||||||
|
} |
||||||
/* (non-Javadoc) |
|
||||||
* @see java.util.List#add(int, java.lang.Object) |
/* (non-Javadoc) |
||||||
*/ |
* @see java.util.List#get(int) |
||||||
public void add(int index, Object element) { |
*/ |
||||||
if (!(element instanceof ActivatableItemI)) |
@Override |
||||||
throw new IllegalArgumentException("only Activatable items"); |
public Object get(int index) { |
||||||
collect.add(index, element); |
return collect.get(index); |
||||||
} |
} |
||||||
|
|
||||||
/* (non-Javadoc) |
/* (non-Javadoc) |
||||||
* @see java.util.List#remove(int) |
* @see java.util.List#set(int, java.lang.Object) |
||||||
*/ |
*/ |
||||||
public Object remove(int index) { |
@Override |
||||||
return collect.remove(index); |
public Object set(int index, Object element) { |
||||||
} |
if (!(element instanceof ActivatableItemI)) throw new IllegalArgumentException("only Activatable items"); |
||||||
|
return collect.set(index, element); |
||||||
/* (non-Javadoc) |
} |
||||||
* @see java.util.List#indexOf(java.lang.Object) |
|
||||||
*/ |
/* (non-Javadoc) |
||||||
public int indexOf(Object o) { |
* @see java.util.List#add(int, java.lang.Object) |
||||||
return collect.indexOf(o); |
*/ |
||||||
} |
@Override |
||||||
|
public void add(int index, Object element) { |
||||||
/* (non-Javadoc) |
if (!(element instanceof ActivatableItemI)) throw new IllegalArgumentException("only Activatable items"); |
||||||
* @see java.util.List#lastIndexOf(java.lang.Object) |
collect.add(index, element); |
||||||
*/ |
} |
||||||
public int lastIndexOf(Object o) { |
|
||||||
return collect.lastIndexOf(o); |
/* (non-Javadoc) |
||||||
} |
* @see java.util.List#remove(int) |
||||||
|
*/ |
||||||
/* (non-Javadoc) |
@Override |
||||||
* @see java.util.List#listIterator() |
public Object remove(int index) { |
||||||
*/ |
return collect.remove(index); |
||||||
public ListIterator listIterator() { |
} |
||||||
return collect.listIterator(); |
|
||||||
} |
/* (non-Javadoc) |
||||||
|
* @see java.util.List#indexOf(java.lang.Object) |
||||||
/* (non-Javadoc) |
*/ |
||||||
* @see java.util.List#listIterator(int) |
@Override |
||||||
*/ |
public int indexOf(Object o) { |
||||||
public ListIterator listIterator(int index) { |
return collect.indexOf(o); |
||||||
return collect.listIterator(index); |
} |
||||||
} |
|
||||||
|
/* (non-Javadoc) |
||||||
/* (non-Javadoc) |
* @see java.util.List#lastIndexOf(java.lang.Object) |
||||||
* @see java.util.List#subList(int, int) |
*/ |
||||||
*/ |
@Override |
||||||
public List subList(int fromIndex, int toIndex) { |
public int lastIndexOf(Object o) { |
||||||
return collect.subList(fromIndex, toIndex); |
return collect.lastIndexOf(o); |
||||||
} |
} |
||||||
public String toString() { |
|
||||||
return "ActivatableItemsList " + size() + " items"; |
/* (non-Javadoc) |
||||||
} |
* @see java.util.List#listIterator() |
||||||
} |
*/ |
||||||
|
@Override |
||||||
|
public ListIterator listIterator() { |
||||||
|
return collect.listIterator(); |
||||||
|
} |
||||||
|
|
||||||
|
/* (non-Javadoc) |
||||||
|
* @see java.util.List#listIterator(int) |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public ListIterator listIterator(int index) { |
||||||
|
return collect.listIterator(index); |
||||||
|
} |
||||||
|
|
||||||
|
/* (non-Javadoc) |
||||||
|
* @see java.util.List#subList(int, int) |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public List subList(int fromIndex, int toIndex) { |
||||||
|
return collect.subList(fromIndex, toIndex); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String toString() { |
||||||
|
return "ActivatableItemsList " + size() + " items"; |
||||||
|
} |
||||||
|
} |
||||||
|
|||||||
@ -1,125 +1,141 @@ |
|||||||
package de.memtext.baseobjects.coll; |
package de.memtext.baseobjects.coll; |
||||||
|
|
||||||
import java.io.Serializable; |
import java.io.Serializable; |
||||||
import java.util.Collection; |
import java.util.Collection; |
||||||
import java.util.Iterator; |
import java.util.Iterator; |
||||||
import java.util.LinkedList; |
import java.util.LinkedList; |
||||||
|
|
||||||
/** |
/** |
||||||
* Basis for the collections, but default the used collection is a |
* Basis for the collections, but default the used collection is a |
||||||
* linkedList, subclasses may change to use a list or set |
* linkedList, subclasses may change to use a list or set |
||||||
* @author MB |
* @author MB |
||||||
* */ |
* */ |
||||||
public class BaseObjectCollection implements Collection,Serializable { |
public class BaseObjectCollection implements Collection, Serializable { |
||||||
protected Collection collect; |
protected Collection collect; |
||||||
private static final long serialVersionUID = 1; |
|
||||||
public BaseObjectCollection() { |
private static final long serialVersionUID = 1; |
||||||
super(); |
|
||||||
collect = new LinkedList(); |
public BaseObjectCollection() { |
||||||
} |
super(); |
||||||
|
collect = new LinkedList(); |
||||||
|
} |
||||||
|
|
||||||
public int size() { |
|
||||||
return collect.size(); |
|
||||||
} |
@Override |
||||||
|
public int size() { |
||||||
/* (non-Javadoc) |
return collect.size(); |
||||||
* @see java.util.Collection#isEmpty() |
} |
||||||
*/ |
|
||||||
public boolean isEmpty() { |
/* (non-Javadoc) |
||||||
return collect.isEmpty(); |
* @see java.util.Collection#isEmpty() |
||||||
} |
*/ |
||||||
|
@Override |
||||||
/* (non-Javadoc) |
public boolean isEmpty() { |
||||||
* @see java.util.Collection#contains(java.lang.Object) |
return collect.isEmpty(); |
||||||
*/ |
} |
||||||
public boolean contains(Object o) { |
|
||||||
return collect.contains(o); |
/* (non-Javadoc) |
||||||
} |
* @see java.util.Collection#contains(java.lang.Object) |
||||||
|
*/ |
||||||
/* (non-Javadoc) |
@Override |
||||||
* @see java.util.Collection#iterator() |
public boolean contains(Object o) { |
||||||
*/ |
return collect.contains(o); |
||||||
public Iterator iterator() { |
} |
||||||
return collect.iterator(); |
|
||||||
} |
/* (non-Javadoc) |
||||||
|
* @see java.util.Collection#iterator() |
||||||
/* (non-Javadoc) |
*/ |
||||||
* @see java.util.Collection#toArray() |
@Override |
||||||
*/ |
public Iterator iterator() { |
||||||
public Object[] toArray() { |
return collect.iterator(); |
||||||
return collect.toArray(); |
} |
||||||
} |
|
||||||
|
/* (non-Javadoc) |
||||||
/* (non-Javadoc) |
* @see java.util.Collection#toArray() |
||||||
* @see java.util.Collection#toArray(java.lang.Object[]) |
*/ |
||||||
*/ |
@Override |
||||||
public Object[] toArray(Object[] a) { |
public Object[] toArray() { |
||||||
return collect.toArray(a); |
return collect.toArray(); |
||||||
} |
} |
||||||
|
|
||||||
|
/* (non-Javadoc) |
||||||
|
* @see java.util.Collection#toArray(java.lang.Object[]) |
||||||
|
*/ |
||||||
/* (non-Javadoc) |
@Override |
||||||
* @see java.util.Collection#containsAll(java.util.Collection) |
public Object[] toArray(Object[] a) { |
||||||
*/ |
return collect.toArray(a); |
||||||
public boolean containsAll(Collection c) { |
} |
||||||
return collect.containsAll(c); |
|
||||||
} |
|
||||||
|
|
||||||
/* (non-Javadoc) |
|
||||||
* @see java.util.Collection#addAll(java.util.Collection) |
/* (non-Javadoc) |
||||||
*/ |
* @see java.util.Collection#containsAll(java.util.Collection) |
||||||
public boolean addAll(Collection c) { |
*/ |
||||||
return collect.addAll(c); |
@Override |
||||||
} |
public boolean containsAll(Collection c) { |
||||||
|
return collect.containsAll(c); |
||||||
/* (non-Javadoc) |
} |
||||||
* @see java.util.Collection#removeAll(java.util.Collection) |
|
||||||
*/ |
/* (non-Javadoc) |
||||||
public boolean removeAll(Collection c) { |
* @see java.util.Collection#addAll(java.util.Collection) |
||||||
return collect.removeAll(c); |
*/ |
||||||
} |
@Override |
||||||
|
public boolean addAll(Collection c) { |
||||||
/* (non-Javadoc) |
return collect.addAll(c); |
||||||
* @see java.util.Collection#retainAll(java.util.Collection) |
} |
||||||
*/ |
|
||||||
public boolean retainAll(Collection c) { |
/* (non-Javadoc) |
||||||
return collect.retainAll(c); |
* @see java.util.Collection#removeAll(java.util.Collection) |
||||||
} |
*/ |
||||||
|
@Override |
||||||
/* (non-Javadoc) |
public boolean removeAll(Collection c) { |
||||||
* @see java.util.Collection#clear() |
return collect.removeAll(c); |
||||||
*/ |
} |
||||||
public void clear() { |
|
||||||
collect.clear(); |
/* (non-Javadoc) |
||||||
} |
* @see java.util.Collection#retainAll(java.util.Collection) |
||||||
|
*/ |
||||||
/* (non-Javadoc) |
@Override |
||||||
* @see java.util.Collection#add(java.lang.Object) |
public boolean retainAll(Collection c) { |
||||||
*/ |
return collect.retainAll(c); |
||||||
public boolean add(Object o) { |
} |
||||||
if (o==null) throw new IllegalArgumentException("can't add null value"); |
|
||||||
return collect.add(o); |
/* (non-Javadoc) |
||||||
} |
* @see java.util.Collection#clear() |
||||||
|
*/ |
||||||
/* (non-Javadoc) |
@Override |
||||||
* @see java.util.Collection#remove(java.lang.Object) |
public void clear() { |
||||||
*/ |
collect.clear(); |
||||||
public boolean remove(Object o) { |
} |
||||||
return collect.remove(o); |
|
||||||
} |
/* (non-Javadoc) |
||||||
|
* @see java.util.Collection#add(java.lang.Object) |
||||||
|
*/ |
||||||
/** |
@Override |
||||||
* Only shallow copy |
public boolean add(Object o) { |
||||||
*/ |
if (o == null) throw new IllegalArgumentException("can't add null value"); |
||||||
protected Object clone() throws CloneNotSupportedException { |
return collect.add(o); |
||||||
BaseObjectCollection c=new BaseObjectCollection(); |
} |
||||||
c.addAll(this); |
|
||||||
return c; |
/* (non-Javadoc) |
||||||
} |
* @see java.util.Collection#remove(java.lang.Object) |
||||||
} |
*/ |
||||||
|
@Override |
||||||
|
public boolean remove(Object o) { |
||||||
|
return collect.remove(o); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Only shallow copy |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
protected Object clone() throws CloneNotSupportedException { |
||||||
|
BaseObjectCollection c = new BaseObjectCollection(); |
||||||
|
c.addAll(this); |
||||||
|
return c; |
||||||
|
} |
||||||
|
} |
||||||
//Created on 30.1.2004
|
//Created on 30.1.2004
|
||||||
@ -1,108 +1,107 @@ |
|||||||
package de.memtext.baseobjects.coll; |
package de.memtext.baseobjects.coll; |
||||||
|
|
||||||
import java.io.Serializable; |
import java.io.Serializable; |
||||||
import java.util.Collection; |
import java.util.Collection; |
||||||
import java.util.Iterator; |
import java.util.Iterator; |
||||||
|
|
||||||
import de.memtext.baseobjects.IdObjectI; |
import de.memtext.baseobjects.IdObjectI; |
||||||
import de.memtext.util.StringUtils; |
import de.memtext.util.StringUtils; |
||||||
|
|
||||||
/** |
/** |
||||||
* |
* |
||||||
* @author MB |
* @author MB |
||||||
* */ |
* */ |
||||||
public class IdObjectCollection |
public class IdObjectCollection extends BaseObjectCollection implements Collection, Serializable { |
||||||
extends BaseObjectCollection |
private static final long serialVersionUID = 1; |
||||||
implements Collection ,Serializable{ |
|
||||||
private static final long serialVersionUID = 1; |
public IdObjectCollection() { |
||||||
public IdObjectCollection() { |
super(); |
||||||
super(); |
} |
||||||
} |
|
||||||
/** |
/** |
||||||
* |
* |
||||||
* @param id |
* @param id |
||||||
* @return object |
* @return object |
||||||
* @throws IllegalArgumentException if nothing found |
* @throws IllegalArgumentException if nothing found |
||||||
*/ |
*/ |
||||||
public IdObjectI getById(Object id) { |
public IdObjectI getById(Object id) { |
||||||
IdObjectI test, result = null; |
IdObjectI test, result = null; |
||||||
for (Iterator it = collect.iterator(); it.hasNext();) { |
for (Iterator it = collect.iterator(); it.hasNext();) { |
||||||
test = (IdObjectI) it.next(); |
test = (IdObjectI) it.next(); |
||||||
if ((id == null && test.getId() == null) |
if ((id == null && test.getId() == null) || (test.getId() != null && test.getId().equals(id))) { |
||||||
|| (test.getId() != null && test.getId().equals(id))) { |
result = test; |
||||||
result = test; |
break; |
||||||
break; |
} |
||||||
} |
} |
||||||
} |
if (result == null) throw new IllegalArgumentException("No element with id " + id + " found!"); |
||||||
if (result == null) |
return result; |
||||||
throw new IllegalArgumentException( |
} |
||||||
"No element with id " + id + " found!"); |
|
||||||
return result; |
/** |
||||||
} |
* like '12','34','343' |
||||||
/** |
* useful for creating sqls like where x in (...) |
||||||
* like '12','34','343' |
* @return |
||||||
* useful for creating sqls like where x in (...) |
*/ |
||||||
* @return |
public String getIdsApostropheString() { |
||||||
*/ |
StringBuffer result = new StringBuffer(); |
||||||
public String getIdsApostropheString() { |
IdObjectI test; |
||||||
StringBuffer result = new StringBuffer(); |
for (Iterator it = collect.iterator(); it.hasNext();) { |
||||||
IdObjectI test; |
test = (IdObjectI) it.next(); |
||||||
for (Iterator it = collect.iterator(); it.hasNext();) { |
result.append("'" + test.getId() + "',"); |
||||||
test = (IdObjectI) it.next(); |
} |
||||||
result.append("'" + test.getId() + "',"); |
StringUtils.deleteLastChar(result); |
||||||
} |
return result.toString(); |
||||||
StringUtils.deleteLastChar(result); |
} |
||||||
return result.toString(); |
|
||||||
} |
public boolean containsItemWithId(Object id) { |
||||||
public boolean containsItemWithId(Object id) { |
boolean result = false; |
||||||
boolean result = false; |
IdObjectI test; |
||||||
IdObjectI test; |
for (Iterator it = collect.iterator(); it.hasNext();) { |
||||||
for (Iterator it = collect.iterator(); it.hasNext();) { |
test = (IdObjectI) it.next(); |
||||||
test = (IdObjectI) it.next(); |
if (test.getId().equals(id)) { |
||||||
if (test.getId().equals(id)) { |
result = true; |
||||||
result = true; |
break; |
||||||
break; |
} |
||||||
} |
} |
||||||
} |
return result; |
||||||
return result; |
} |
||||||
} |
|
||||||
/** |
/** |
||||||
* Checks if the collection contains only the ids given in the param collection ids |
* Checks if the collection contains only the ids given in the param collection ids |
||||||
* @param Collection ids |
* @param Collection ids |
||||||
* @return |
* @return |
||||||
*/ |
*/ |
||||||
public boolean consistsOfIds(Collection ids) { |
public boolean consistsOfIds(Collection ids) { |
||||||
|
|
||||||
if (this.size() != ids.size()) |
if (this.size() != ids.size()) return false; |
||||||
return false; |
boolean result = true; |
||||||
boolean result = true; |
for (Iterator it = ids.iterator(); it.hasNext();) { |
||||||
for (Iterator it = ids.iterator(); it.hasNext();) { |
Object id = it.next(); |
||||||
Object id = it.next(); |
try { |
||||||
try { |
Object dummy = getById(id); |
||||||
Object dummy = getById(id); |
} catch (IllegalArgumentException e) { |
||||||
} catch (IllegalArgumentException e) { |
result = false; |
||||||
result = false; |
break; |
||||||
break; |
} |
||||||
} |
} |
||||||
} |
return result; |
||||||
return result; |
} |
||||||
} |
|
||||||
|
@Override |
||||||
public boolean add(Object o) { |
public boolean add(Object o) { |
||||||
if (o == null) |
if (o == null) throw new IllegalArgumentException("can't add null value"); |
||||||
throw new IllegalArgumentException("can't add null value"); |
if (!(o instanceof IdObjectI)) throw new IllegalArgumentException("only named IdObjects allowed"); |
||||||
if (!(o instanceof IdObjectI)) |
return collect.add(o); |
||||||
throw new IllegalArgumentException("only named IdObjects allowed"); |
} |
||||||
return collect.add(o); |
|
||||||
} |
/** |
||||||
|
* Only shallow copy |
||||||
/** |
*/ |
||||||
* Only shallow copy |
@Override |
||||||
*/ |
protected Object clone() throws CloneNotSupportedException { |
||||||
protected Object clone() throws CloneNotSupportedException { |
IdObjectCollection c = new IdObjectCollection(); |
||||||
IdObjectCollection c=new IdObjectCollection(); |
c.addAll(this); |
||||||
c.addAll(this); |
return c; |
||||||
return c; |
} |
||||||
} |
} |
||||||
} |
|
||||||
//Created on 30.1.2004
|
//Created on 30.1.2004
|
||||||
@ -1,84 +1,97 @@ |
|||||||
package de.memtext.baseobjects.coll; |
package de.memtext.baseobjects.coll; |
||||||
|
|
||||||
import java.util.Collection; |
import java.util.Collection; |
||||||
import java.util.Iterator; |
import java.util.Iterator; |
||||||
import java.util.LinkedList; |
import java.util.LinkedList; |
||||||
import java.util.List; |
import java.util.List; |
||||||
import java.util.ListIterator; |
import java.util.ListIterator; |
||||||
|
|
||||||
import de.memtext.baseobjects.IdObjectI; |
import de.memtext.baseobjects.IdObjectI; |
||||||
import de.memtext.util.StringUtils; |
import de.memtext.util.StringUtils; |
||||||
|
|
||||||
/** |
/** |
||||||
* |
* |
||||||
* @author MB |
* @author MB |
||||||
* */ |
* */ |
||||||
public class IdObjectList extends IdObjectCollection implements List { |
public class IdObjectList extends IdObjectCollection implements List { |
||||||
private static final long serialVersionUID = 1; |
private static final long serialVersionUID = 1; |
||||||
public IdObjectList() { |
|
||||||
super(); |
public IdObjectList() { |
||||||
collect=new LinkedList(); |
super(); |
||||||
} |
collect = new LinkedList(); |
||||||
|
} |
||||||
|
|
||||||
public Object get(int pos) |
|
||||||
{ |
@Override |
||||||
return ((List)collect).get(pos); |
public Object get(int pos) { |
||||||
} |
return ((List) collect).get(pos); |
||||||
|
} |
||||||
public boolean addAll(int arg0, Collection arg1) { |
|
||||||
return ((List)collect).addAll(arg0,arg1); |
@Override |
||||||
} |
public boolean addAll(int arg0, Collection arg1) { |
||||||
|
return ((List) collect).addAll(arg0, arg1); |
||||||
public Object set(int arg0, Object arg1) { |
} |
||||||
return ((List)collect).set(arg0,arg1); |
|
||||||
} |
@Override |
||||||
|
public Object set(int arg0, Object arg1) { |
||||||
public void add(int pos, Object arg1) { |
return ((List) collect).set(arg0, arg1); |
||||||
((List)collect).add(pos,arg1); |
} |
||||||
} |
|
||||||
|
@Override |
||||||
public Object remove(int arg0) { |
public void add(int pos, Object arg1) { |
||||||
return ((List)collect).remove(arg0); |
((List) collect).add(pos, arg1); |
||||||
} |
} |
||||||
|
|
||||||
|
@Override |
||||||
public ListIterator listIterator(int arg0) { |
public Object remove(int arg0) { |
||||||
return ((List)collect).listIterator(arg0); |
return ((List) collect).remove(arg0); |
||||||
} |
} |
||||||
|
|
||||||
public List subList(int arg0, int arg1) { |
|
||||||
return ((List)collect).subList(arg0,arg1); |
@Override |
||||||
} |
public ListIterator listIterator(int arg0) { |
||||||
|
return ((List) collect).listIterator(arg0); |
||||||
public int indexOf(Object arg0) { |
} |
||||||
return ((List)collect).indexOf(arg0); |
|
||||||
} |
@Override |
||||||
|
public List subList(int arg0, int arg1) { |
||||||
public int lastIndexOf(Object arg0) { |
return ((List) collect).subList(arg0, arg1); |
||||||
return ((List)collect).lastIndexOf(arg0); |
} |
||||||
} |
|
||||||
|
@Override |
||||||
public ListIterator listIterator() { |
public int indexOf(Object arg0) { |
||||||
return ((List)collect).listIterator(); |
return ((List) collect).indexOf(arg0); |
||||||
} |
} |
||||||
public String toString() |
|
||||||
{ |
@Override |
||||||
StringBuffer result=new StringBuffer("idobject list:"); |
public int lastIndexOf(Object arg0) { |
||||||
for (Iterator it = this.iterator(); it.hasNext();) { |
return ((List) collect).lastIndexOf(arg0); |
||||||
IdObjectI element = (IdObjectI) it.next(); |
} |
||||||
result.append(element.toString()+","); |
|
||||||
} |
@Override |
||||||
StringUtils.getLastChar(result); |
public ListIterator listIterator() { |
||||||
return result.toString(); |
return ((List) collect).listIterator(); |
||||||
} |
} |
||||||
/** |
|
||||||
* Only shallow copy |
@Override |
||||||
*/ |
public String toString() { |
||||||
protected Object clone() throws CloneNotSupportedException { |
StringBuffer result = new StringBuffer("idobject list:"); |
||||||
IdObjectList c=new IdObjectList(); |
for (Iterator it = this.iterator(); it.hasNext();) { |
||||||
c.addAll(this); |
IdObjectI element = (IdObjectI) it.next(); |
||||||
return c; |
result.append(element.toString() + ","); |
||||||
} |
} |
||||||
} |
StringUtils.getLastChar(result); |
||||||
//Created on 30.1.2004
|
return result.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Only shallow copy |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
protected Object clone() throws CloneNotSupportedException { |
||||||
|
IdObjectList c = new IdObjectList(); |
||||||
|
c.addAll(this); |
||||||
|
return c; |
||||||
|
} |
||||||
|
} |
||||||
|
//Created on 30.1.2004
|
||||||
|
|||||||
@ -1,24 +1,26 @@ |
|||||||
package de.memtext.baseobjects.coll; |
package de.memtext.baseobjects.coll; |
||||||
|
|
||||||
import java.util.HashSet; |
import java.util.HashSet; |
||||||
import java.util.Set; |
import java.util.Set; |
||||||
|
|
||||||
public class IdObjectSet extends IdObjectCollection implements Set { |
public class IdObjectSet extends IdObjectCollection implements Set { |
||||||
private static final long serialVersionUID = 1; |
private static final long serialVersionUID = 1; |
||||||
public IdObjectSet() { |
|
||||||
super(); |
public IdObjectSet() { |
||||||
collect=new HashSet(); |
super(); |
||||||
} |
collect = new HashSet(); |
||||||
|
} |
||||||
|
|
||||||
/** |
|
||||||
* Only shallow copy |
/** |
||||||
*/ |
* Only shallow copy |
||||||
protected Object clone() throws CloneNotSupportedException { |
*/ |
||||||
IdObjectSet c=new IdObjectSet(); |
@Override |
||||||
c.addAll(this); |
protected Object clone() throws CloneNotSupportedException { |
||||||
return c; |
IdObjectSet c = new IdObjectSet(); |
||||||
} |
c.addAll(this); |
||||||
} |
return c; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
//Created on 30.1.2004
|
//Created on 30.1.2004
|
||||||
@ -1,138 +1,135 @@ |
|||||||
package de.memtext.baseobjects.coll; |
package de.memtext.baseobjects.coll; |
||||||
|
|
||||||
import java.io.Serializable; |
import java.io.Serializable; |
||||||
import java.util.Collection; |
import java.util.Collection; |
||||||
import java.util.Iterator; |
import java.util.Iterator; |
||||||
|
|
||||||
import de.memtext.baseobjects.NamedIdObject; |
import de.memtext.baseobjects.NamedIdObjectI; |
||||||
import de.memtext.baseobjects.NamedIdObjectI; |
import de.memtext.util.EqualsUtil; |
||||||
import de.memtext.util.EqualsUtil; |
import de.memtext.util.StringUtils; |
||||||
import de.memtext.util.StringUtils; |
|
||||||
|
/** |
||||||
/** |
* |
||||||
* |
* @author MB |
||||||
* @author MB |
*/ |
||||||
*/ |
public class NamedIdObjectCollection extends NamedObjectCollection implements Collection, Serializable { |
||||||
public class NamedIdObjectCollection extends NamedObjectCollection implements |
private static final long serialVersionUID = 1; |
||||||
Collection, Serializable { |
|
||||||
private static final long serialVersionUID = 1; |
public NamedIdObjectCollection() { |
||||||
public NamedIdObjectCollection() { |
super(); |
||||||
super(); |
} |
||||||
} |
|
||||||
|
/** |
||||||
/** |
* |
||||||
* |
* @param id |
||||||
* @param id |
* @return object |
||||||
* @return object |
* @throws IllegalArgumentException |
||||||
* @throws IllegalArgumentException |
* if nothing found |
||||||
* if nothing found |
*/ |
||||||
*/ |
public NamedIdObjectI getById(Object id) { |
||||||
public NamedIdObjectI getById(Object id) { |
NamedIdObjectI test, result = null; |
||||||
NamedIdObjectI test, result = null; |
for (Iterator it = collect.iterator(); it.hasNext();) { |
||||||
for (Iterator it = collect.iterator(); it.hasNext();) { |
test = (NamedIdObjectI) it.next(); |
||||||
test = (NamedIdObjectI) it.next(); |
if ((id == null && test.getId() == null) || (test.getId() != null && test.getId().equals(id))) { |
||||||
if ((id == null && test.getId() == null) |
result = test; |
||||||
|| (test.getId() != null && test.getId().equals(id))) { |
break; |
||||||
result = test; |
} |
||||||
break; |
} |
||||||
} |
if (result == null) throw new IllegalArgumentException("No element with id " + id + " found!"); |
||||||
} |
return result; |
||||||
if (result == null) |
} |
||||||
throw new IllegalArgumentException("No element with id " + id |
|
||||||
+ " found!"); |
/** |
||||||
return result; |
* like '12','34','343' useful for creating sqls like where x in (...) |
||||||
} |
* |
||||||
|
* @return |
||||||
/** |
*/ |
||||||
* like '12','34','343' useful for creating sqls like where x in (...) |
public String getIdsApostropheString() { |
||||||
* |
StringBuffer result = new StringBuffer(); |
||||||
* @return |
NamedIdObjectI test; |
||||||
*/ |
for (Iterator it = collect.iterator(); it.hasNext();) { |
||||||
public String getIdsApostropheString() { |
test = (NamedIdObjectI) it.next(); |
||||||
StringBuffer result = new StringBuffer(); |
result.append("'" + test.getId() + "',"); |
||||||
NamedIdObjectI test; |
} |
||||||
for (Iterator it = collect.iterator(); it.hasNext();) { |
StringUtils.deleteLastChar(result); |
||||||
test = (NamedIdObjectI) it.next(); |
return result.toString(); |
||||||
result.append("'" + test.getId() + "',"); |
} |
||||||
} |
|
||||||
StringUtils.deleteLastChar(result); |
@Override |
||||||
return result.toString(); |
public boolean containsItemWithName(String name) { |
||||||
} |
boolean result = false; |
||||||
|
NamedIdObjectI test; |
||||||
public boolean containsItemWithName(String name) { |
for (Iterator it = collect.iterator(); it.hasNext();) { |
||||||
boolean result = false; |
test = (NamedIdObjectI) it.next(); |
||||||
NamedIdObjectI test; |
if (test.getName().equals(name)) { |
||||||
for (Iterator it = collect.iterator(); it.hasNext();) { |
result = true; |
||||||
test = (NamedIdObjectI) it.next(); |
break; |
||||||
if (test.getName().equals(name)) { |
} |
||||||
result = true; |
} |
||||||
break; |
return result; |
||||||
} |
} |
||||||
} |
|
||||||
return result; |
public boolean containsItemWithId(Object id) { |
||||||
} |
boolean result = false; |
||||||
|
NamedIdObjectI test; |
||||||
public boolean containsItemWithId(Object id) { |
for (Iterator it = collect.iterator(); it.hasNext();) { |
||||||
boolean result = false; |
test = (NamedIdObjectI) it.next(); |
||||||
NamedIdObjectI test; |
if (EqualsUtil.areEqual(test.getId(), id)) { |
||||||
for (Iterator it = collect.iterator(); it.hasNext();) { |
result = true; |
||||||
test = (NamedIdObjectI) it.next(); |
break; |
||||||
if (EqualsUtil.areEqual(test.getId(),id)) { |
} |
||||||
result = true; |
} |
||||||
break; |
return result; |
||||||
} |
} |
||||||
} |
|
||||||
return result; |
/** |
||||||
} |
* Checks if the collection contains only the ids given in the param |
||||||
|
* collection ids |
||||||
/** |
* |
||||||
* Checks if the collection contains only the ids given in the param |
* @param Collection |
||||||
* collection ids |
* ids |
||||||
* |
* @return |
||||||
* @param Collection |
*/ |
||||||
* ids |
public boolean consistsOfIds(Collection ids) { |
||||||
* @return |
|
||||||
*/ |
if (this.size() != ids.size()) return false; |
||||||
public boolean consistsOfIds(Collection ids) { |
boolean result = true; |
||||||
|
for (Iterator it = ids.iterator(); it.hasNext();) { |
||||||
if (this.size() != ids.size()) |
Object id = it.next(); |
||||||
return false; |
try { |
||||||
boolean result = true; |
Object dummy = getById(id); |
||||||
for (Iterator it = ids.iterator(); it.hasNext();) { |
} catch (IllegalArgumentException e) { |
||||||
Object id = it.next(); |
result = false; |
||||||
try { |
break; |
||||||
Object dummy = getById(id); |
} |
||||||
} catch (IllegalArgumentException e) { |
} |
||||||
result = false; |
return result; |
||||||
break; |
} |
||||||
} |
|
||||||
} |
@Override |
||||||
return result; |
public boolean add(Object o) { |
||||||
} |
if (o == null) throw new IllegalArgumentException("can't add null value"); |
||||||
|
if (!(o instanceof NamedIdObjectI)) throw new IllegalArgumentException("only named IdObjects allowed"); |
||||||
public boolean add(Object o) { |
return collect.add(o); |
||||||
if (o == null) |
} |
||||||
throw new IllegalArgumentException("can't add null value"); |
|
||||||
if (!(o instanceof NamedIdObjectI)) |
@Override |
||||||
throw new IllegalArgumentException("only named IdObjects allowed"); |
public String toString() { |
||||||
return collect.add(o); |
StringBuffer result = new StringBuffer(size() + " NamedIdObjects: "); |
||||||
} |
for (Iterator it = this.iterator(); it.hasNext();) { |
||||||
|
NamedIdObjectI element = (NamedIdObjectI) it.next(); |
||||||
public String toString() { |
result.append(element + " - "); |
||||||
StringBuffer result = new StringBuffer(size() + " NamedIdObjects: "); |
} |
||||||
for (Iterator it = this.iterator(); it.hasNext();) { |
return result.toString(); |
||||||
NamedIdObjectI element = (NamedIdObjectI) it.next(); |
} |
||||||
result.append(element + " - "); |
|
||||||
} |
/** |
||||||
return result.toString(); |
* Only shallow copy |
||||||
} |
*/ |
||||||
|
@Override |
||||||
/** |
protected Object clone() throws CloneNotSupportedException { |
||||||
* Only shallow copy |
NamedIdObjectCollection c = new NamedIdObjectCollection(); |
||||||
*/ |
c.addAll(this); |
||||||
protected Object clone() throws CloneNotSupportedException { |
return c; |
||||||
NamedIdObjectCollection c=new NamedIdObjectCollection(); |
} |
||||||
c.addAll(this); |
|
||||||
return c; |
|
||||||
} |
|
||||||
} |
} |
||||||
@ -1,71 +1,82 @@ |
|||||||
package de.memtext.baseobjects.coll; |
package de.memtext.baseobjects.coll; |
||||||
|
|
||||||
import java.util.Collection; |
import java.util.Collection; |
||||||
import java.util.LinkedList; |
import java.util.LinkedList; |
||||||
import java.util.List; |
import java.util.List; |
||||||
import java.util.ListIterator; |
import java.util.ListIterator; |
||||||
|
|
||||||
/** |
/** |
||||||
* |
* |
||||||
* @author MB |
* @author MB |
||||||
* */ |
* */ |
||||||
public class NamedIdObjectList extends NamedIdObjectCollection implements List { |
public class NamedIdObjectList extends NamedIdObjectCollection implements List { |
||||||
private static final long serialVersionUID = 1; |
private static final long serialVersionUID = 1; |
||||||
public NamedIdObjectList() { |
|
||||||
super(); |
public NamedIdObjectList() { |
||||||
collect=new LinkedList(); |
super(); |
||||||
} |
collect = new LinkedList(); |
||||||
|
} |
||||||
|
|
||||||
public Object get(int pos) |
|
||||||
{ |
@Override |
||||||
return ((List)collect).get(pos); |
public Object get(int pos) { |
||||||
} |
return ((List) collect).get(pos); |
||||||
|
} |
||||||
public boolean addAll(int arg0, Collection arg1) { |
|
||||||
return ((List)collect).addAll(arg0,arg1); |
@Override |
||||||
} |
public boolean addAll(int arg0, Collection arg1) { |
||||||
|
return ((List) collect).addAll(arg0, arg1); |
||||||
public Object set(int arg0, Object arg1) { |
} |
||||||
return ((List)collect).set(arg0,arg1); |
|
||||||
} |
@Override |
||||||
|
public Object set(int arg0, Object arg1) { |
||||||
public void add(int pos, Object arg1) { |
return ((List) collect).set(arg0, arg1); |
||||||
((List)collect).add(pos,arg1); |
} |
||||||
} |
|
||||||
|
@Override |
||||||
public Object remove(int arg0) { |
public void add(int pos, Object arg1) { |
||||||
return ((List)collect).remove(arg0); |
((List) collect).add(pos, arg1); |
||||||
} |
} |
||||||
|
|
||||||
|
@Override |
||||||
public ListIterator listIterator(int arg0) { |
public Object remove(int arg0) { |
||||||
return ((List)collect).listIterator(arg0); |
return ((List) collect).remove(arg0); |
||||||
} |
} |
||||||
|
|
||||||
public List subList(int arg0, int arg1) { |
|
||||||
return ((List)collect).subList(arg0,arg1); |
@Override |
||||||
} |
public ListIterator listIterator(int arg0) { |
||||||
|
return ((List) collect).listIterator(arg0); |
||||||
public int indexOf(Object arg0) { |
} |
||||||
return ((List)collect).indexOf(arg0); |
|
||||||
} |
@Override |
||||||
|
public List subList(int arg0, int arg1) { |
||||||
public int lastIndexOf(Object arg0) { |
return ((List) collect).subList(arg0, arg1); |
||||||
return ((List)collect).lastIndexOf(arg0); |
} |
||||||
} |
|
||||||
|
@Override |
||||||
public ListIterator listIterator() { |
public int indexOf(Object arg0) { |
||||||
return ((List)collect).listIterator(); |
return ((List) collect).indexOf(arg0); |
||||||
} |
} |
||||||
|
|
||||||
/** |
@Override |
||||||
* Only shallow copy |
public int lastIndexOf(Object arg0) { |
||||||
*/ |
return ((List) collect).lastIndexOf(arg0); |
||||||
protected Object clone() throws CloneNotSupportedException { |
} |
||||||
NamedIdObjectList c=new NamedIdObjectList(); |
|
||||||
c.addAll(this); |
@Override |
||||||
return c; |
public ListIterator listIterator() { |
||||||
} |
return ((List) collect).listIterator(); |
||||||
|
} |
||||||
} |
|
||||||
|
/** |
||||||
|
* Only shallow copy |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
protected Object clone() throws CloneNotSupportedException { |
||||||
|
NamedIdObjectList c = new NamedIdObjectList(); |
||||||
|
c.addAll(this); |
||||||
|
return c; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|||||||
@ -1,35 +1,38 @@ |
|||||||
package de.memtext.baseobjects.coll; |
package de.memtext.baseobjects.coll; |
||||||
|
|
||||||
import java.util.HashSet; |
import java.util.HashSet; |
||||||
import java.util.Set; |
import java.util.Set; |
||||||
|
|
||||||
public class NamedIdObjectSet extends NamedIdObjectCollection implements Set { |
public class NamedIdObjectSet extends NamedIdObjectCollection implements Set { |
||||||
private static final long serialVersionUID = 1; |
private static final long serialVersionUID = 1; |
||||||
/** |
|
||||||
* Default uses a HashSet internally; |
/** |
||||||
* |
* Default uses a HashSet internally; |
||||||
*/ |
* |
||||||
public NamedIdObjectSet() { |
*/ |
||||||
super(); |
public NamedIdObjectSet() { |
||||||
collect=new HashSet(); |
super(); |
||||||
} |
collect = new HashSet(); |
||||||
/** |
} |
||||||
* |
|
||||||
* @param set the implementation of Set interface to use internally |
/** |
||||||
*/ |
* |
||||||
public NamedIdObjectSet(Set set) { |
* @param set the implementation of Set interface to use internally |
||||||
super(); |
*/ |
||||||
collect=set; |
public NamedIdObjectSet(Set set) { |
||||||
} |
super(); |
||||||
|
collect = set; |
||||||
/** |
} |
||||||
* Only shallow copy |
|
||||||
*/ |
/** |
||||||
protected Object clone() throws CloneNotSupportedException { |
* Only shallow copy |
||||||
NamedIdObjectSet c=new NamedIdObjectSet(); |
*/ |
||||||
c.addAll(this); |
@Override |
||||||
return c; |
protected Object clone() throws CloneNotSupportedException { |
||||||
} |
NamedIdObjectSet c = new NamedIdObjectSet(); |
||||||
} |
c.addAll(this); |
||||||
|
return c; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
//Created on 03.12.2003
|
//Created on 03.12.2003
|
||||||
@ -1,82 +1,75 @@ |
|||||||
package de.memtext.baseobjects.coll; |
package de.memtext.baseobjects.coll; |
||||||
|
|
||||||
import java.util.Collection; |
import java.util.Collection; |
||||||
import java.util.Iterator; |
import java.util.Iterator; |
||||||
|
|
||||||
import de.memtext.baseobjects.NamedIdObject; |
import de.memtext.baseobjects.NamedIdObjectWithParentI; |
||||||
import de.memtext.baseobjects.NamedIdObjectI; |
import de.memtext.util.EqualsUtil; |
||||||
import de.memtext.baseobjects.NamedIdObjectWithParent; |
|
||||||
import de.memtext.baseobjects.NamedIdObjectWithParentI; |
public class NamedIdObjectWithParentCollection extends NamedIdObjectCollection implements Collection { |
||||||
import de.memtext.util.EqualsUtil; |
private static final long serialVersionUID = 1; |
||||||
|
|
||||||
public class NamedIdObjectWithParentCollection |
public NamedIdObjectWithParentCollection() { |
||||||
extends NamedIdObjectCollection |
super(); |
||||||
implements Collection { |
} |
||||||
private static final long serialVersionUID = 1; |
|
||||||
public NamedIdObjectWithParentCollection() { |
public boolean containsItemWithParent(Object parent) { |
||||||
super(); |
boolean result = false; |
||||||
} |
NamedIdObjectWithParentI test; |
||||||
|
for (Iterator it = collect.iterator(); it.hasNext();) { |
||||||
public boolean containsItemWithParent(Object parent) { |
test = (NamedIdObjectWithParentI) it.next(); |
||||||
boolean result = false; |
if (EqualsUtil.areEqual(test.getParentKey(), parent)) { |
||||||
NamedIdObjectWithParentI test; |
result = true; |
||||||
for (Iterator it = collect.iterator(); it.hasNext();) { |
break; |
||||||
test = (NamedIdObjectWithParentI) it.next(); |
} |
||||||
if (EqualsUtil.areEqual(test.getParentKey(),parent)) { |
} |
||||||
result = true; |
return result; |
||||||
break; |
} |
||||||
} |
|
||||||
} |
/** |
||||||
return result; |
* get a collection with all objects in the collection that have a |
||||||
} |
* given parentKey |
||||||
/** |
* @param parentKey |
||||||
* get a collection with all objects in the collection that have a |
* @return collection if concrete object is a NamedIdObjectWithParentList also |
||||||
* given parentKey |
* returns a NamedIdObjectWithParentList, same for NamedIdObjectWithParentSet |
||||||
* @param parentKey |
* makes casting possible |
||||||
* @return collection if concrete object is a NamedIdObjectWithParentList also |
*/ |
||||||
* returns a NamedIdObjectWithParentList, same for NamedIdObjectWithParentSet |
public NamedIdObjectWithParentCollection getByParent(Object parentKey) { |
||||||
* makes casting possible |
NamedIdObjectWithParentCollection result = new NamedIdObjectWithParentCollection(); |
||||||
*/ |
if (this instanceof NamedIdObjectWithParentList) result = new NamedIdObjectWithParentList(); |
||||||
public NamedIdObjectWithParentCollection getByParent(Object parentKey) { |
if (this instanceof NamedIdObjectWithParentSet) result = new NamedIdObjectWithParentSet(); |
||||||
NamedIdObjectWithParentCollection result = |
|
||||||
new NamedIdObjectWithParentCollection(); |
for (Iterator it = this.iterator(); it.hasNext();) { |
||||||
if (this instanceof NamedIdObjectWithParentList) |
NamedIdObjectWithParentI element = (NamedIdObjectWithParentI) it.next(); |
||||||
result = new NamedIdObjectWithParentList(); |
if (EqualsUtil.areEqual(element.getParentKey(), parentKey)) result.add(element); |
||||||
if (this instanceof NamedIdObjectWithParentSet) |
} |
||||||
result = new NamedIdObjectWithParentSet(); |
return result; |
||||||
|
} |
||||||
for (Iterator it = this.iterator(); it.hasNext();) { |
|
||||||
NamedIdObjectWithParentI element = |
public int countItemsWithParent(Object parent) { |
||||||
(NamedIdObjectWithParentI) it.next(); |
return getByParent(parent).size(); |
||||||
if (EqualsUtil.areEqual(element.getParentKey(),parentKey)) |
|
||||||
result.add(element); |
} |
||||||
} |
|
||||||
return result; |
@Override |
||||||
} |
public String toString() { |
||||||
|
StringBuffer result = new StringBuffer(size() + " NamedIdObjectsWithParent: "); |
||||||
public int countItemsWithParent(Object parent) |
for (Iterator it = this.iterator(); it.hasNext();) { |
||||||
{ |
NamedIdObjectWithParentI element = (NamedIdObjectWithParentI) it.next(); |
||||||
return getByParent(parent).size(); |
result.append(element + " - "); |
||||||
|
} |
||||||
} |
return result.toString(); |
||||||
public String toString() |
} |
||||||
{ |
|
||||||
StringBuffer result=new StringBuffer(size()+" NamedIdObjectsWithParent: "); |
/** |
||||||
for (Iterator it = this.iterator(); it.hasNext();) { |
* Only shallow copy |
||||||
NamedIdObjectWithParentI element = (NamedIdObjectWithParentI) it.next(); |
*/ |
||||||
result.append(element+" - "); |
@Override |
||||||
} |
protected Object clone() throws CloneNotSupportedException { |
||||||
return result.toString(); |
NamedIdObjectWithParentCollection c = new NamedIdObjectWithParentCollection(); |
||||||
} |
c.addAll(this); |
||||||
|
return c; |
||||||
/** |
} |
||||||
* Only shallow copy |
} |
||||||
*/ |
|
||||||
protected Object clone() throws CloneNotSupportedException { |
|
||||||
NamedIdObjectWithParentCollection c=new NamedIdObjectWithParentCollection(); |
|
||||||
c.addAll(this); |
|
||||||
return c; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
//Created on 18.11.2003
|
//Created on 18.11.2003
|
||||||
@ -1,66 +1,77 @@ |
|||||||
package de.memtext.baseobjects.coll; |
package de.memtext.baseobjects.coll; |
||||||
|
|
||||||
import java.util.Collection; |
import java.util.Collection; |
||||||
import java.util.LinkedList; |
import java.util.LinkedList; |
||||||
import java.util.List; |
import java.util.List; |
||||||
import java.util.ListIterator; |
import java.util.ListIterator; |
||||||
|
|
||||||
public class NamedIdObjectWithParentList extends NamedIdObjectWithParentCollection implements List { |
public class NamedIdObjectWithParentList extends NamedIdObjectWithParentCollection implements List { |
||||||
private static final long serialVersionUID = 1; |
private static final long serialVersionUID = 1; |
||||||
public NamedIdObjectWithParentList() { |
|
||||||
super(); |
public NamedIdObjectWithParentList() { |
||||||
collect=new LinkedList(); |
super(); |
||||||
} |
collect = new LinkedList(); |
||||||
public Object get(int pos) |
} |
||||||
{ |
|
||||||
return ((List)collect).get(pos); |
@Override |
||||||
} |
public Object get(int pos) { |
||||||
|
return ((List) collect).get(pos); |
||||||
public boolean addAll(int arg0, Collection arg1) { |
} |
||||||
return ((List)collect).addAll(arg0,arg1); |
@Override |
||||||
} |
public boolean addAll(int arg0, Collection arg1) { |
||||||
|
return ((List) collect).addAll(arg0, arg1); |
||||||
public Object set(int arg0, Object arg1) { |
} |
||||||
return ((List)collect).set(arg0,arg1); |
|
||||||
} |
@Override |
||||||
|
public Object set(int arg0, Object arg1) { |
||||||
public void add(int pos, Object arg1) { |
return ((List) collect).set(arg0, arg1); |
||||||
((List)collect).add(pos,arg1); |
} |
||||||
} |
|
||||||
|
@Override |
||||||
public Object remove(int arg0) { |
public void add(int pos, Object arg1) { |
||||||
return ((List)collect).remove(arg0); |
((List) collect).add(pos, arg1); |
||||||
} |
} |
||||||
|
|
||||||
|
@Override |
||||||
public ListIterator listIterator(int arg0) { |
public Object remove(int arg0) { |
||||||
return ((List)collect).listIterator(arg0); |
return ((List) collect).remove(arg0); |
||||||
} |
} |
||||||
|
|
||||||
public List subList(int arg0, int arg1) { |
@Override |
||||||
return ((List)collect).subList(arg0,arg1); |
public ListIterator listIterator(int arg0) { |
||||||
} |
return ((List) collect).listIterator(arg0); |
||||||
|
} |
||||||
public int indexOf(Object arg0) { |
|
||||||
return ((List)collect).indexOf(arg0); |
@Override |
||||||
} |
public List subList(int arg0, int arg1) { |
||||||
|
return ((List) collect).subList(arg0, arg1); |
||||||
public int lastIndexOf(Object arg0) { |
} |
||||||
return ((List)collect).lastIndexOf(arg0); |
|
||||||
} |
@Override |
||||||
|
public int indexOf(Object arg0) { |
||||||
public ListIterator listIterator() { |
return ((List) collect).indexOf(arg0); |
||||||
return ((List)collect).listIterator(); |
} |
||||||
} |
|
||||||
/** |
@Override |
||||||
* Only shallow copy |
public int lastIndexOf(Object arg0) { |
||||||
*/ |
return ((List) collect).lastIndexOf(arg0); |
||||||
protected Object clone() throws CloneNotSupportedException { |
} |
||||||
NamedIdObjectWithParentList c=new NamedIdObjectWithParentList(); |
|
||||||
c.addAll(this); |
@Override |
||||||
return c; |
public ListIterator listIterator() { |
||||||
} |
return ((List) collect).listIterator(); |
||||||
} |
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Only shallow copy |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
protected Object clone() throws CloneNotSupportedException { |
||||||
|
NamedIdObjectWithParentList c = new NamedIdObjectWithParentList(); |
||||||
|
c.addAll(this); |
||||||
|
return c; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
//Created on 18.11.2003
|
//Created on 18.11.2003
|
||||||
@ -1,25 +1,27 @@ |
|||||||
package de.memtext.baseobjects.coll; |
package de.memtext.baseobjects.coll; |
||||||
|
|
||||||
import java.util.HashSet; |
import java.util.HashSet; |
||||||
import java.util.Set; |
import java.util.Set; |
||||||
|
|
||||||
public class NamedIdObjectWithParentSet extends NamedIdObjectWithParentCollection implements Set { |
public class NamedIdObjectWithParentSet extends NamedIdObjectWithParentCollection implements Set { |
||||||
private static final long serialVersionUID = 1; |
private static final long serialVersionUID = 1; |
||||||
public NamedIdObjectWithParentSet() { |
|
||||||
super(); |
public NamedIdObjectWithParentSet() { |
||||||
collect=new HashSet(); |
super(); |
||||||
} |
collect = new HashSet(); |
||||||
|
} |
||||||
|
|
||||||
/** |
|
||||||
* Only shallow copy |
/** |
||||||
*/ |
* Only shallow copy |
||||||
protected Object clone() throws CloneNotSupportedException { |
*/ |
||||||
NamedIdObjectWithParentCollection c=new NamedIdObjectWithParentSet(); |
@Override |
||||||
c.addAll(this); |
protected Object clone() throws CloneNotSupportedException { |
||||||
return c; |
NamedIdObjectWithParentCollection c = new NamedIdObjectWithParentSet(); |
||||||
} |
c.addAll(this); |
||||||
} |
return c; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
//Created on 03.12.2003
|
//Created on 03.12.2003
|
||||||
@ -1,102 +1,99 @@ |
|||||||
package de.memtext.baseobjects.coll; |
package de.memtext.baseobjects.coll; |
||||||
|
|
||||||
import java.io.Serializable; |
import java.io.Serializable; |
||||||
import java.util.Collection; |
import java.util.Collection; |
||||||
import java.util.Iterator; |
import java.util.Iterator; |
||||||
|
|
||||||
import de.memtext.baseobjects.NamedObjectI; |
import de.memtext.baseobjects.NamedObjectI; |
||||||
import de.memtext.util.EqualsUtil; |
import de.memtext.util.EqualsUtil; |
||||||
import de.memtext.util.StringUtils; |
import de.memtext.util.StringUtils; |
||||||
|
|
||||||
/** |
/** |
||||||
* |
* |
||||||
* @author MB |
* @author MB |
||||||
* */ |
* */ |
||||||
public class NamedObjectCollection |
public class NamedObjectCollection extends BaseObjectCollection implements Collection, Serializable { |
||||||
extends BaseObjectCollection |
private static final long serialVersionUID = 1; |
||||||
implements Collection,Serializable { |
|
||||||
private static final long serialVersionUID = 1; |
public NamedObjectCollection() { |
||||||
|
super(); |
||||||
public NamedObjectCollection() { |
} |
||||||
super(); |
|
||||||
} |
|
||||||
|
/** |
||||||
|
* Tries to find an element with the given name |
||||||
/** |
* @param name |
||||||
* Tries to find an element with the given name |
* @return first element with given name |
||||||
* @param name |
* @throws IllegalArgumentException if nothing found |
||||||
* @return first element with given name |
*/ |
||||||
* @throws IllegalArgumentException if nothing found |
public NamedObjectI getByName(String name) { |
||||||
*/public NamedObjectI getByName(String name) { |
NamedObjectI test, result = null; |
||||||
NamedObjectI test, result = null; |
for (Iterator it = collect.iterator(); it.hasNext();) { |
||||||
for (Iterator it = collect.iterator(); it.hasNext();) { |
test = (NamedObjectI) it.next(); |
||||||
test = (NamedObjectI) it.next(); |
if (test.getName().equals(name)) { |
||||||
if (test.getName().equals(name)) { |
result = test; |
||||||
result = test; |
break; |
||||||
break; |
} |
||||||
} |
} |
||||||
} |
if (result == null) throw new IllegalArgumentException("No element with name " + name + " found."); |
||||||
if (result == null) |
return result; |
||||||
throw new IllegalArgumentException( |
} |
||||||
"No element with name " + name + " found."); |
|
||||||
return result; |
/** |
||||||
} |
* like '12','34','343' |
||||||
/** |
* useful for creating sqls like where x in (...) |
||||||
* like '12','34','343' |
* @return '' if collection is empty |
||||||
* useful for creating sqls like where x in (...) |
*/ |
||||||
* @return '' if collection is empty |
|
||||||
*/ |
public String getNamesApostropheString() { |
||||||
|
StringBuffer result = new StringBuffer(); |
||||||
public String getNamesApostropheString() { |
NamedObjectI test; |
||||||
StringBuffer result = new StringBuffer(); |
for (Iterator it = collect.iterator(); it.hasNext();) { |
||||||
NamedObjectI test; |
test = (NamedObjectI) it.next(); |
||||||
for (Iterator it = collect.iterator(); it.hasNext();) { |
result.append("'" + test.getName() + "',"); |
||||||
test = (NamedObjectI) it.next(); |
} |
||||||
result.append("'" + test.getName() + "',"); |
StringUtils.deleteLastChar(result); |
||||||
} |
if (result.length() == 0) result.append("''"); |
||||||
StringUtils.deleteLastChar(result); |
return result.toString(); |
||||||
if (result.length() == 0) |
} |
||||||
result.append("''"); |
|
||||||
return result.toString(); |
public boolean containsItemWithName(String name) { |
||||||
} |
boolean result = false; |
||||||
|
NamedObjectI test; |
||||||
public boolean containsItemWithName(String name) { |
for (Iterator it = collect.iterator(); it.hasNext();) { |
||||||
boolean result = false; |
test = (NamedObjectI) it.next(); |
||||||
NamedObjectI test; |
if (EqualsUtil.areEqual(test.getName(), name)) { |
||||||
for (Iterator it = collect.iterator(); it.hasNext();) { |
result = true; |
||||||
test = (NamedObjectI) it.next(); |
break; |
||||||
if (EqualsUtil.areEqual(test.getName(),name)) |
} |
||||||
{ |
} |
||||||
result = true; |
return result; |
||||||
break; |
} |
||||||
} |
|
||||||
} |
@Override |
||||||
return result; |
public boolean add(Object o) { |
||||||
} |
if (o == null) throw new IllegalArgumentException("can't add null value"); |
||||||
|
if (!(o instanceof NamedObjectI)) throw new IllegalArgumentException("only named Objects allowed"); |
||||||
public boolean add(Object o) { |
return collect.add(o); |
||||||
if (o == null) |
} |
||||||
throw new IllegalArgumentException("can't add null value"); |
|
||||||
if (!(o instanceof NamedObjectI)) |
@Override |
||||||
throw new IllegalArgumentException("only named Objects allowed"); |
public String toString() { |
||||||
return collect.add(o); |
StringBuffer result = new StringBuffer(size() + " NamedObjects: "); |
||||||
} |
for (Iterator it = this.iterator(); it.hasNext();) { |
||||||
public String toString() |
NamedObjectI element = (NamedObjectI) it.next(); |
||||||
{ |
result.append(element + " - "); |
||||||
StringBuffer result=new StringBuffer(size()+" NamedObjects: "); |
} |
||||||
for (Iterator it = this.iterator(); it.hasNext();) { |
return result.toString(); |
||||||
NamedObjectI element = (NamedObjectI) it.next(); |
} |
||||||
result.append(element+" - "); |
|
||||||
} |
/** |
||||||
return result.toString(); |
* Only shallow copy |
||||||
} |
*/ |
||||||
|
@Override |
||||||
/** |
protected Object clone() throws CloneNotSupportedException { |
||||||
* Only shallow copy |
NamedObjectCollection c = new NamedObjectCollection(); |
||||||
*/ |
c.addAll(this); |
||||||
protected Object clone() throws CloneNotSupportedException { |
return c; |
||||||
NamedObjectCollection c=new NamedObjectCollection(); |
} |
||||||
c.addAll(this); |
} |
||||||
return c; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|||||||
@ -1,70 +1,79 @@ |
|||||||
package de.memtext.baseobjects.coll; |
package de.memtext.baseobjects.coll; |
||||||
|
|
||||||
import java.util.Collection; |
import java.util.Collection; |
||||||
import java.util.LinkedList; |
import java.util.LinkedList; |
||||||
import java.util.List; |
import java.util.List; |
||||||
import java.util.ListIterator; |
import java.util.ListIterator; |
||||||
|
|
||||||
|
|
||||||
/** |
/** |
||||||
* |
* |
||||||
* @author MB |
* @author MB |
||||||
* */ |
* */ |
||||||
public class NamedObjectList extends NamedObjectCollection implements List { |
public class NamedObjectList extends NamedObjectCollection implements List { |
||||||
private static final long serialVersionUID = 1; |
private static final long serialVersionUID = 1; |
||||||
public NamedObjectList() { |
|
||||||
super(); |
public NamedObjectList() { |
||||||
collect = new LinkedList(); |
super(); |
||||||
} |
collect = new LinkedList(); |
||||||
|
} |
||||||
public Object get(int pos) |
|
||||||
{ |
@Override |
||||||
return ((List)collect).get(pos); |
public Object get(int pos) { |
||||||
} |
return ((List) collect).get(pos); |
||||||
|
} |
||||||
public boolean addAll(int arg0, Collection arg1) { |
@Override |
||||||
return ((List)collect).addAll(arg0,arg1); |
public boolean addAll(int arg0, Collection arg1) { |
||||||
} |
return ((List) collect).addAll(arg0, arg1); |
||||||
|
} |
||||||
public Object set(int arg0, Object arg1) { |
|
||||||
return ((List)collect).set(arg0,arg1); |
@Override |
||||||
} |
public Object set(int arg0, Object arg1) { |
||||||
|
return ((List) collect).set(arg0, arg1); |
||||||
public void add(int pos, Object arg1) { |
} |
||||||
((List)collect).add(pos,arg1); |
|
||||||
} |
@Override |
||||||
|
public void add(int pos, Object arg1) { |
||||||
public Object remove(int arg0) { |
((List) collect).add(pos, arg1); |
||||||
return ((List)collect).remove(arg0); |
} |
||||||
} |
|
||||||
|
@Override |
||||||
|
public Object remove(int arg0) { |
||||||
public ListIterator listIterator(int arg0) { |
return ((List) collect).remove(arg0); |
||||||
return ((List)collect).listIterator(arg0); |
} |
||||||
} |
|
||||||
|
@Override |
||||||
public List subList(int arg0, int arg1) { |
public ListIterator listIterator(int arg0) { |
||||||
return ((List)collect).subList(arg0,arg1); |
return ((List) collect).listIterator(arg0); |
||||||
} |
} |
||||||
|
|
||||||
public int indexOf(Object arg0) { |
@Override |
||||||
return ((List)collect).indexOf(arg0); |
public List subList(int arg0, int arg1) { |
||||||
} |
return ((List) collect).subList(arg0, arg1); |
||||||
|
} |
||||||
public int lastIndexOf(Object arg0) { |
|
||||||
return ((List)collect).lastIndexOf(arg0); |
@Override |
||||||
} |
public int indexOf(Object arg0) { |
||||||
|
return ((List) collect).indexOf(arg0); |
||||||
public ListIterator listIterator() { |
} |
||||||
return ((List)collect).listIterator(); |
|
||||||
} |
@Override |
||||||
|
public int lastIndexOf(Object arg0) { |
||||||
/** |
return ((List) collect).lastIndexOf(arg0); |
||||||
* Only shallow copy |
} |
||||||
*/ |
|
||||||
protected Object clone() throws CloneNotSupportedException { |
@Override |
||||||
NamedObjectCollection c=new NamedObjectList(); |
public ListIterator listIterator() { |
||||||
c.addAll(this); |
return ((List) collect).listIterator(); |
||||||
return c; |
} |
||||||
} |
|
||||||
} |
/** |
||||||
|
* Only shallow copy |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
protected Object clone() throws CloneNotSupportedException { |
||||||
|
NamedObjectCollection c = new NamedObjectList(); |
||||||
|
c.addAll(this); |
||||||
|
return c; |
||||||
|
} |
||||||
|
} |
||||||
|
|||||||
@ -1,29 +1,31 @@ |
|||||||
package de.memtext.baseobjects.coll; |
package de.memtext.baseobjects.coll; |
||||||
|
|
||||||
import java.util.HashSet; |
import java.util.HashSet; |
||||||
import java.util.Set; |
import java.util.Set; |
||||||
|
|
||||||
public class NamedObjectSet extends NamedObjectCollection implements Set { |
public class NamedObjectSet extends NamedObjectCollection implements Set { |
||||||
private static final long serialVersionUID = 1; |
private static final long serialVersionUID = 1; |
||||||
public NamedObjectSet() { |
|
||||||
super(); |
public NamedObjectSet() { |
||||||
collect=new HashSet(); |
super(); |
||||||
} |
collect = new HashSet(); |
||||||
|
} |
||||||
public NamedObjectSet(Set set) { |
|
||||||
super(); |
public NamedObjectSet(Set set) { |
||||||
if (set==null)throw new IllegalArgumentException("set must not be null"); |
super(); |
||||||
collect=set; |
if (set == null) throw new IllegalArgumentException("set must not be null"); |
||||||
} |
collect = set; |
||||||
|
} |
||||||
/** |
|
||||||
* Only shallow copy |
/** |
||||||
*/ |
* Only shallow copy |
||||||
protected Object clone() throws CloneNotSupportedException { |
*/ |
||||||
NamedObjectCollection c=new NamedObjectSet(); |
@Override |
||||||
c.addAll(this); |
protected Object clone() throws CloneNotSupportedException { |
||||||
return c; |
NamedObjectCollection c = new NamedObjectSet(); |
||||||
} |
c.addAll(this); |
||||||
} |
return c; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
//Created on 02.12.2003 at 19:08:30
|
//Created on 02.12.2003 at 19:08:30
|
||||||
@ -1,89 +1,92 @@ |
|||||||
package de.memtext.buttons; |
package de.memtext.buttons; |
||||||
|
|
||||||
import java.util.Enumeration; |
import java.util.Enumeration; |
||||||
|
|
||||||
import javax.swing.ButtonGroup; |
import javax.swing.ButtonGroup; |
||||||
import javax.swing.ButtonModel; |
import javax.swing.JLabel; |
||||||
import javax.swing.JLabel; |
import javax.swing.JPanel; |
||||||
import javax.swing.JPanel; |
import javax.swing.JRadioButton; |
||||||
import javax.swing.JRadioButton; |
|
||||||
|
public class ButtonGroupPanel extends JPanel { |
||||||
public class ButtonGroupPanel extends JPanel { |
ButtonGroup group = new ButtonGroup(); |
||||||
ButtonGroup group = new ButtonGroup(); |
|
||||||
ButtonWithValue hiddenNoSelectionButton = new ButtonWithValue("", null); |
ButtonWithValue hiddenNoSelectionButton = new ButtonWithValue("", null); |
||||||
|
|
||||||
public ButtonGroupPanel() { |
public ButtonGroupPanel() { |
||||||
this(null); |
this(null); |
||||||
} |
} |
||||||
public ButtonGroupPanel(String header) { |
|
||||||
super(); |
public ButtonGroupPanel(String header) { |
||||||
if (header != null) |
super(); |
||||||
this.add(new JLabel(header)); |
if (header != null) this.add(new JLabel(header)); |
||||||
|
|
||||||
hiddenNoSelectionButton.setVisible(false); |
hiddenNoSelectionButton.setVisible(false); |
||||||
hiddenNoSelectionButton.setSelected(true); |
hiddenNoSelectionButton.setSelected(true); |
||||||
group.add(hiddenNoSelectionButton); |
group.add(hiddenNoSelectionButton); |
||||||
} |
} |
||||||
public void addCategory(String label, Object value,boolean isSelected) { |
|
||||||
ButtonWithValue b = new ButtonWithValue(label, value); |
public void addCategory(String label, Object value, boolean isSelected) { |
||||||
this.add(b); |
ButtonWithValue b = new ButtonWithValue(label, value); |
||||||
group.add(b); |
this.add(b); |
||||||
b.setSelected(isSelected); |
group.add(b); |
||||||
} |
b.setSelected(isSelected); |
||||||
public void addCategory(String label, Object value) { |
} |
||||||
addCategory(label, value,false); |
|
||||||
} |
public void addCategory(String label, Object value) { |
||||||
|
addCategory(label, value, false); |
||||||
public void addCategory(String label, int i) { |
} |
||||||
addCategory(label, new Integer(i)); |
|
||||||
} |
public void addCategory(String label, int i) { |
||||||
public void addCategory(String label, int i,boolean isSelected) { |
addCategory(label, Integer.valueOf(i)); |
||||||
addCategory(label, new Integer(i),isSelected); |
} |
||||||
} |
|
||||||
/** |
public void addCategory(String label, int i, boolean isSelected) { |
||||||
* If you pass null as an argument no element will be selected |
addCategory(label, Integer.valueOf(i), isSelected); |
||||||
* @param label |
} |
||||||
*/ |
|
||||||
public void setSelected(String label) { |
/** |
||||||
if (label == null) |
* If you pass null as an argument no element will be selected |
||||||
hiddenNoSelectionButton.setSelected(true); |
* @param label |
||||||
else |
*/ |
||||||
for (Enumeration en = group.getElements(); |
public void setSelected(String label) { |
||||||
en.hasMoreElements(); |
if (label == null) |
||||||
) { |
hiddenNoSelectionButton.setSelected(true); |
||||||
ButtonWithValue b = (ButtonWithValue) en.nextElement(); |
else |
||||||
if (b.getText().equals(label)) { |
for (Enumeration en = group.getElements(); en.hasMoreElements();) { |
||||||
b.doClick(); |
ButtonWithValue b = (ButtonWithValue) en.nextElement(); |
||||||
break; |
if (b.getText().equals(label)) { |
||||||
} |
b.doClick(); |
||||||
} |
break; |
||||||
} |
} |
||||||
|
} |
||||||
public Object getSelectedValue() { |
} |
||||||
ButtonWithValue selectedButton=null; |
|
||||||
for (Enumeration en = group.getElements(); |
public Object getSelectedValue() { |
||||||
en.hasMoreElements(); |
ButtonWithValue selectedButton = null; |
||||||
) { |
for (Enumeration en = group.getElements(); en.hasMoreElements();) { |
||||||
ButtonWithValue b = (ButtonWithValue) en.nextElement(); |
ButtonWithValue b = (ButtonWithValue) en.nextElement(); |
||||||
if (b.isSelected()) { |
if (b.isSelected()) { |
||||||
selectedButton=b; |
selectedButton = b; |
||||||
break; |
break; |
||||||
} |
} |
||||||
} |
} |
||||||
return selectedButton.getValue(); |
return selectedButton.getValue(); |
||||||
} |
} |
||||||
class ButtonWithValue extends JRadioButton { |
|
||||||
private Object value; |
class ButtonWithValue extends JRadioButton { |
||||||
ButtonWithValue(String label, Object value) { |
private Object value; |
||||||
super(label); |
|
||||||
this.value = value; |
ButtonWithValue(String label, Object value) { |
||||||
} |
super(label); |
||||||
Object getValue() { |
this.value = value; |
||||||
return value; |
} |
||||||
} |
|
||||||
|
Object getValue() { |
||||||
} |
return value; |
||||||
|
} |
||||||
} |
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
//Created on 17.02.2004 at 13:40:06
|
//Created on 17.02.2004 at 13:40:06
|
||||||
@ -1,39 +1,38 @@ |
|||||||
package de.memtext.buttons; |
package de.memtext.buttons; |
||||||
|
|
||||||
import javax.swing.JButton; |
import javax.swing.JButton; |
||||||
|
|
||||||
/** |
/** |
||||||
* @author MB |
* @author MB |
||||||
* |
* |
||||||
* JButtons not as static variables, because can be used in different |
* JButtons not as static variables, because can be used in different |
||||||
* places in one application, setting one be invisible would make all invisible |
* places in one application, setting one be invisible would make all invisible |
||||||
*/ |
*/ |
||||||
public class Standard { |
public class Standard { |
||||||
|
|
||||||
/** |
/** |
||||||
* Constructor for Standard. |
* Constructor for Standard. |
||||||
*/ |
*/ |
||||||
private Standard() { |
private Standard() { |
||||||
super(); |
super(); |
||||||
} |
} |
||||||
|
|
||||||
public static JButton getCopy() |
public static JButton getCopy() { |
||||||
{ |
|
||||||
|
JButton copy = new JButton(de.memtext.icons.MBStandardIcons.getCopy()); |
||||||
JButton copy=new JButton(de.memtext.icons.MBStandardIcons.getCopy()); |
copy.setToolTipText("Kopieren"); |
||||||
copy.setToolTipText("Kopieren"); |
copy.setActionCommand("copy"); |
||||||
copy.setActionCommand("copy"); |
return copy; |
||||||
return copy; |
|
||||||
|
} |
||||||
} |
|
||||||
public static JButton getCopyWithText() |
public static JButton getCopyWithText() { |
||||||
{ |
|
||||||
|
JButton copy = new JButton("Kopieren", de.memtext.icons.MBStandardIcons.getCopy()); |
||||||
JButton copy=new JButton("Kopieren",de.memtext.icons.MBStandardIcons.getCopy()); |
copy.setToolTipText("Kopieren"); |
||||||
copy.setToolTipText("Kopieren"); |
copy.setActionCommand("copy"); |
||||||
copy.setActionCommand("copy"); |
return copy; |
||||||
return copy; |
|
||||||
|
} |
||||||
} |
|
||||||
|
} |
||||||
} |
|
||||||
|
|||||||
@ -1,43 +1,44 @@ |
|||||||
/* |
/* |
||||||
* Copyright (c) 2001-2004, The HSQL Development Group All rights reserved. |
* Copyright (c) 2001-2004, The HSQL Development Group All rights reserved. |
||||||
* |
* |
||||||
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
||||||
* modification, are permitted provided that the following conditions are met: |
* modification, are permitted provided that the following conditions are met: |
||||||
* |
* |
||||||
* Redistributions of source code must retain the above copyright notice, this |
* Redistributions of source code must retain the above copyright notice, this |
||||||
* list of conditions and the following disclaimer. |
* list of conditions and the following disclaimer. |
||||||
* |
* |
||||||
* Redistributions in binary form must reproduce the above copyright notice, |
* Redistributions in binary form must reproduce the above copyright notice, |
||||||
* this list of conditions and the following disclaimer in the documentation |
* this list of conditions and the following disclaimer in the documentation |
||||||
* and/or other materials provided with the distribution. |
* and/or other materials provided with the distribution. |
||||||
* |
* |
||||||
* Neither the name of the HSQL Development Group nor the names of its |
* Neither the name of the HSQL Development Group nor the names of its |
||||||
* contributors may be used to endorse or promote products derived from this |
* contributors may be used to endorse or promote products derived from this |
||||||
* software without specific prior written permission. |
* software without specific prior written permission. |
||||||
* |
* |
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG, OR |
* ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG, OR |
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
||||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
||||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
||||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
||||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||||
*/ |
*/ |
||||||
|
|
||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import java.util.ListResourceBundle; |
import java.util.ListResourceBundle; |
||||||
/** |
|
||||||
* Resources for HsqlStandaloneMgr. |
/** |
||||||
* For other locales extend AbstractHsqlStandloneMgrResources, i.e. |
* Resources for HsqlStandaloneMgr. |
||||||
* by copying HsqlStandaloneMgrResources_de to your locale |
* For other locales extend AbstractHsqlStandloneMgrResources, i.e. |
||||||
*/ |
* by copying HsqlStandaloneMgrResources_de to your locale |
||||||
public abstract class AbstractHsqlStandaloneMgrResources extends ListResourceBundle { |
*/ |
||||||
|
public abstract class AbstractHsqlStandaloneMgrResources extends ListResourceBundle { |
||||||
public abstract String getDbInUseBy(String dbname,String user); |
|
||||||
} |
public abstract String getDbInUseBy(String dbname, String user); |
||||||
|
} |
||||||
|
|
||||||
|
|||||||
@ -1,174 +1,158 @@ |
|||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import java.io.File; |
import java.io.File; |
||||||
import java.sql.Connection; |
import java.sql.Connection; |
||||||
import java.sql.DriverManager; |
import java.sql.DriverManager; |
||||||
import java.sql.ResultSet; |
import java.sql.ResultSet; |
||||||
import java.sql.SQLException; |
import java.sql.SQLException; |
||||||
import java.sql.Statement; |
import java.sql.Statement; |
||||||
import java.text.DateFormat; |
import java.text.DateFormat; |
||||||
import java.text.ParseException; |
import java.text.ParseException; |
||||||
import java.text.SimpleDateFormat; |
import java.text.SimpleDateFormat; |
||||||
import java.util.Date; |
import java.util.Date; |
||||||
/** |
|
||||||
* Additional procedures for HSQLDB |
/** |
||||||
* make sure that this class in the classpath. |
* Additional procedures for HSQLDB |
||||||
* To constantly add it to hsql. |
* make sure that this class in the classpath. |
||||||
* Go to the directory where your hsqldb.jar is located |
* To constantly add it to hsql. |
||||||
* Call jar -xf hsqlAddOn.jar |
* Go to the directory where your hsqldb.jar is located |
||||||
* jar -uf hsqldb.jar org/hsqldb/Library2.class |
* Call jar -xf hsqlAddOn.jar |
||||||
* Delete the directory org. |
* jar -uf hsqldb.jar org/hsqldb/Library2.class |
||||||
* |
* Delete the directory org. |
||||||
* Open your Database in Database Manager and execute |
* |
||||||
* the following commands once: |
* Open your Database in Database Manager and execute |
||||||
* GRANT ALL ON CLASS "org.hsqldb.Library2" TO PUBLIC and |
* the following commands once: |
||||||
* CREATE ALIAS COPYFROM FOR "org.hsqldb.Library2.copyFrom" |
* GRANT ALL ON CLASS "org.hsqldb.Library2" TO PUBLIC and |
||||||
|
* CREATE ALIAS COPYFROM FOR "org.hsqldb.Library2.copyFrom" |
||||||
|
|
||||||
*/ |
|
||||||
public class AddProc { |
*/ |
||||||
private static DateFormat dfUS = new SimpleDateFormat("yyyy-MM-dd"); |
public class AddProc { |
||||||
|
private static DateFormat dfUS = new SimpleDateFormat("yyyy-MM-dd"); |
||||||
private AddProc() { |
|
||||||
super(); |
private AddProc() { |
||||||
} |
super(); |
||||||
/** |
} |
||||||
* Fills regular tables with values from a CSV-file. |
|
||||||
* Similar to Postgres COPY FROM command. |
/** |
||||||
* |
* Fills regular tables with values from a CSV-file. |
||||||
* If you want to fill your table TEST with data from test.csv |
* Similar to Postgres COPY FROM command. |
||||||
* make sure that this class in the classpath and that<br> |
* |
||||||
* GRANT ALL ON CLASS "org.hsqldb.Library2" TO PUBLIC;<br> |
* If you want to fill your table TEST with data from test.csv |
||||||
CREATE ALIAS COPYFROM FOR "org.hsqldb.Library2.copyFrom"<br> |
* make sure that this class in the classpath and that<br> |
||||||
* has been called in your database at some point. |
* GRANT ALL ON CLASS "org.hsqldb.Library2" TO PUBLIC;<br> |
||||||
<br> |
CREATE ALIAS COPYFROM FOR "org.hsqldb.Library2.copyFrom"<br> |
||||||
* Then execute <br> |
* has been called in your database at some point. |
||||||
* CALL COPYFROM('TEST','test.csv',null)<br> |
<br> |
||||||
* <br> |
* Then execute <br> |
||||||
* if your not using , but | as a field separator<br> |
* CALL COPYFROM('TEST','test.csv',null)<br> |
||||||
CALL COPYFROM('TEST','test.csv','fs=|')<br> |
* <br> |
||||||
<br> |
* if your not using , but | as a field separator<br> |
||||||
* |
CALL COPYFROM('TEST','test.csv','fs=|')<br> |
||||||
* @param con - Connection is automatically handed over by HSQL |
<br> |
||||||
* @param table - the name of the table that is to be filled |
* |
||||||
* if you created your table with "", e.g. create table "myData" <br> |
* @param con - Connection is automatically handed over by HSQL |
||||||
* also pass the inverted commans like this CALL COPYFROM('\"myData\"','test.csv',null); |
* @param table - the name of the table that is to be filled |
||||||
* |
* if you created your table with "", e.g. create table "myData" <br> |
||||||
* @param file - the filename of the CSV-file |
* also pass the inverted commans like this CALL COPYFROM('\"myData\"','test.csv',null); |
||||||
* @param options - you can specify options separated by ; |
* |
||||||
* which are described in the text table documentation e.g.<br> |
* @param file - the filename of the CSV-file |
||||||
* fs=| to use pipe instead of default comma as field separator or<br> |
* @param options - you can specify options separated by ; |
||||||
* |
* which are described in the text table documentation e.g.<br> |
||||||
* fs=|;vs=.;lvs=~" varchar separator, longvarchar separator<br> |
* fs=| to use pipe instead of default comma as field separator or<br> |
||||||
* ignore_first=true; ignore first line<br> |
* |
||||||
* all_quoted=true or<br> |
* fs=|;vs=.;lvs=~" varchar separator, longvarchar separator<br> |
||||||
* encoding=UTF-8 if you don't have ASCII<br> |
* ignore_first=true; ignore first line<br> |
||||||
* @throws SQLException |
* all_quoted=true or<br> |
||||||
*/ |
* encoding=UTF-8 if you don't have ASCII<br> |
||||||
public static String copyFrom( |
* @throws SQLException |
||||||
Connection con, |
*/ |
||||||
String table, |
public static String copyFrom(Connection con, String table, String file, String options) throws SQLException { |
||||||
String file, |
if (table == null || table.equals("")) throw new IllegalArgumentException("Table must not be null or empty"); |
||||||
String options) |
if (file == null || file.equals("")) throw new IllegalArgumentException("File must not be null or empty"); |
||||||
throws SQLException { |
File f = new File(file); |
||||||
if (table == null || table.equals("")) |
if (!f.exists()) throw new IllegalArgumentException("source file " + file + " doesn't exist"); |
||||||
throw new IllegalArgumentException("Table must not be null or empty"); |
|
||||||
if (file == null || file.equals("")) |
//normally created tables are in UPPERCASE in the metadata,
|
||||||
throw new IllegalArgumentException("File must not be null or empty"); |
//but tables in inverted commas (create table "myData")
|
||||||
File f = new File(file); |
//are stored case sensitive
|
||||||
if (!f.exists()) |
String tableNameInMetaData; |
||||||
throw new IllegalArgumentException( |
if (table.startsWith("\"")) |
||||||
"source file " + file + " doesn't exist"); |
tableNameInMetaData = table.substring(1, table.length() - 1); |
||||||
|
else |
||||||
//normally created tables are in UPPERCASE in the metadata,
|
tableNameInMetaData = table.toUpperCase(); |
||||||
//but tables in inverted commas (create table "myData")
|
StringBuffer buf = new StringBuffer("create temp text table TMP_COPYFROM("); |
||||||
//are stored case sensitive
|
|
||||||
String tableNameInMetaData; |
ResultSet rs = con.getMetaData().getColumns(null, null, tableNameInMetaData, null); |
||||||
if (table.startsWith("\"")) |
String colname, coltype; |
||||||
tableNameInMetaData = table.substring(1, table.length() - 1); |
boolean tableFound = false; |
||||||
else |
while (rs.next()) { |
||||||
tableNameInMetaData = table.toUpperCase(); |
tableFound = true; |
||||||
StringBuffer buf = |
colname = rs.getObject(4).toString(); |
||||||
new StringBuffer("create temp text table TMP_COPYFROM("); |
coltype = rs.getObject(6).toString(); |
||||||
|
buf.append(colname + " " + coltype + ","); |
||||||
ResultSet rs = |
} |
||||||
con.getMetaData().getColumns(null, null, tableNameInMetaData, null); |
rs.close(); |
||||||
String colname, coltype; |
if (!tableFound) throw new SQLException("Copy from failed - table " + table + " not found"); |
||||||
boolean tableFound = false; |
buf.deleteCharAt(buf.lastIndexOf(",")); |
||||||
while (rs.next()) { |
buf.append("); SET TABLE TMP_COPYFROM SOURCE \"" + file); |
||||||
tableFound = true; |
if (options != null) buf.append(";" + options); |
||||||
colname = rs.getObject(4).toString(); |
buf.append("\";"); |
||||||
coltype = rs.getObject(6).toString(); |
buf.append("insert into " + table + " select * from TMP_COPYFROM"); |
||||||
buf.append(colname + " " + coltype + ","); |
System.out.println(buf); |
||||||
} |
Statement stmt = con.createStatement(); |
||||||
rs.close(); |
try { |
||||||
if (!tableFound) |
stmt.execute(buf.toString()); |
||||||
throw new SQLException( |
return "success"; |
||||||
"Copy from failed - table " |
} |
||||||
+ table |
//finally is executed before returning whether an exception occurs or not
|
||||||
+ " not found"); |
finally { |
||||||
buf.deleteCharAt(buf.lastIndexOf(",")); |
stmt.execute("drop table TMP_COPYFROM IF EXISTS"); |
||||||
buf.append("); SET TABLE TMP_COPYFROM SOURCE \"" + file); |
} |
||||||
if (options != null) |
|
||||||
buf.append(";" + options); |
} |
||||||
buf.append("\";"); |
|
||||||
buf.append("insert into " + table + " select * from TMP_COPYFROM"); |
|
||||||
System.out.println(buf); |
public static String toDate(String year, String month, String day) throws ParseException { |
||||||
Statement stmt = con.createStatement(); |
String result; |
||||||
try { |
Date d = dfUS.parse(year.trim() + "-" + month.trim() + "-" + day.trim()); |
||||||
stmt.execute(buf.toString()); |
result = dfUS.format(d); |
||||||
return "success"; |
return result; |
||||||
} |
} |
||||||
//finally is executed before returning whether an exception occurs or not
|
|
||||||
finally { |
public static String toDate(String year, int month, int day) throws ParseException { |
||||||
stmt.execute("drop table TMP_COPYFROM IF EXISTS"); |
return toDate(year + "", month + "", day + ""); |
||||||
} |
} |
||||||
|
|
||||||
} |
public static String toDate(int year, int month, int day) throws ParseException { |
||||||
|
return toDate(year + "", month + "", day + ""); |
||||||
|
|
||||||
public static String toDate(String year, String month, String day) |
} |
||||||
throws ParseException { |
|
||||||
String result; |
public static void main(String a[]) { |
||||||
Date d = |
Connection conn = null; |
||||||
dfUS.parse(year.trim() + "-" + month.trim() + "-" + day.trim()); |
try { |
||||||
result = dfUS.format(d); |
Class.forName("org.hsqldb.jdbcDriver"); |
||||||
return result; |
conn = DriverManager.getConnection("jdbc:hsqldb:test", "sa", ""); |
||||||
} |
java.sql.Statement stmt = conn.createStatement(); |
||||||
public static String toDate(String year, int month, int day) |
stmt.execute("drop table \"test\" if exists;create table \"test\" (col1 integer,col2 varchar, col3 double,col4 date)"); |
||||||
throws ParseException { |
copyFrom(conn, "\"test\"", "test.csv", "fs=;"); |
||||||
return toDate(year + "", month + "", day + ""); |
System.out.println("2"); |
||||||
} |
copyFrom(conn, "\"test\"", "test.csv", "fs=;"); |
||||||
public static String toDate(int year, int month, int day) |
stmt.close(); |
||||||
throws ParseException { |
|
||||||
return toDate(year + "", month + "", day + ""); |
} catch (ClassNotFoundException e) { |
||||||
|
e.printStackTrace(); |
||||||
} |
} catch (SQLException e) { |
||||||
public static void main(String a[]) { |
e.printStackTrace(); |
||||||
Connection conn = null; |
} finally { |
||||||
try { |
try { |
||||||
Class.forName("org.hsqldb.jdbcDriver"); |
conn.close(); |
||||||
conn = DriverManager.getConnection("jdbc:hsqldb:test", "sa", ""); |
} catch (SQLException e1) { |
||||||
java.sql.Statement stmt = conn.createStatement(); |
e1.printStackTrace(); |
||||||
stmt.execute( |
} |
||||||
"drop table \"test\" if exists;create table \"test\" (col1 integer,col2 varchar, col3 double,col4 date)"); |
} |
||||||
copyFrom(conn, "\"test\"", "test.csv", "fs=;"); |
} |
||||||
System.out.println("2"); |
} |
||||||
copyFrom(conn, "\"test\"", "test.csv", "fs=;"); |
|
||||||
stmt.close(); |
|
||||||
|
|
||||||
} catch (ClassNotFoundException e) { |
|
||||||
e.printStackTrace(); |
|
||||||
} catch (SQLException e) { |
|
||||||
e.printStackTrace(); |
|
||||||
} finally { |
|
||||||
try { |
|
||||||
conn.close(); |
|
||||||
} catch (SQLException e1) { |
|
||||||
e1.printStackTrace(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
//Created on 08.03.2004 at 13:48:03
|
//Created on 08.03.2004 at 13:48:03
|
||||||
@ -1,43 +1,49 @@ |
|||||||
/* |
/* |
||||||
* Created on 23.07.2003 |
* Created on 23.07.2003 |
||||||
* |
* |
||||||
* To change the template for this generated file go to |
* To change the template for this generated file go to |
||||||
* Window>Preferences>Java>Code Generation>Code and Comments |
* Window>Preferences>Java>Code Generation>Code and Comments |
||||||
*/ |
*/ |
||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import java.util.Collection; |
import java.util.Collection; |
||||||
import java.util.Iterator; |
import java.util.Iterator; |
||||||
import java.util.LinkedList; |
import java.util.LinkedList; |
||||||
|
|
||||||
/** |
/** |
||||||
* @author Gast |
* @author Gast |
||||||
* |
* |
||||||
* To change the template for this generated type comment go to |
* To change the template for this generated type comment go to |
||||||
* Window>Preferences>Java>Code Generation>Code and Comments |
* Window>Preferences>Java>Code Generation>Code and Comments |
||||||
*/ |
*/ |
||||||
public class Comparison { |
public class Comparison { |
||||||
private String name; |
private String name; |
||||||
private Collection units = new LinkedList(); |
|
||||||
public Comparison(String name) { |
private Collection units = new LinkedList(); |
||||||
this.name = name; |
|
||||||
} |
public Comparison(String name) { |
||||||
public void addUnit(ComparisonUnit unit) { |
this.name = name; |
||||||
units.add(unit); |
} |
||||||
|
|
||||||
} |
public void addUnit(ComparisonUnit unit) { |
||||||
public Iterator iterator() |
units.add(unit); |
||||||
{ |
|
||||||
return units.iterator(); |
} |
||||||
} |
|
||||||
public int getUnitCount() |
public Iterator iterator() { |
||||||
{ |
return units.iterator(); |
||||||
return units.size(); |
} |
||||||
} |
|
||||||
public void removeUnit(ComparisonUnit unit) { |
public int getUnitCount() { |
||||||
units.remove(unit); |
return units.size(); |
||||||
} |
} |
||||||
public String toString() { |
|
||||||
return name; |
public void removeUnit(ComparisonUnit unit) { |
||||||
} |
units.remove(unit); |
||||||
} |
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String toString() { |
||||||
|
return name; |
||||||
|
} |
||||||
|
} |
||||||
|
|||||||
@ -1,50 +1,51 @@ |
|||||||
/* |
/* |
||||||
* Created on 23.07.2003 |
* Created on 23.07.2003 |
||||||
* |
* |
||||||
* To change the template for this generated file go to |
* To change the template for this generated file go to |
||||||
* Window>Preferences>Java>Code Generation>Code and Comments |
* Window>Preferences>Java>Code Generation>Code and Comments |
||||||
*/ |
*/ |
||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
/** |
/** |
||||||
* @author Gast |
* @author Gast |
||||||
* |
* |
||||||
* To change the template for this generated type comment go to |
* To change the template for this generated type comment go to |
||||||
* Window>Preferences>Java>Code Generation>Code and Comments |
* Window>Preferences>Java>Code Generation>Code and Comments |
||||||
*/ |
*/ |
||||||
public class ComparisonUnit { |
public class ComparisonUnit { |
||||||
private String name,sql; |
private String name, sql; |
||||||
public ComparisonUnit(String name,String sql) |
|
||||||
{ |
public ComparisonUnit(String name, String sql) { |
||||||
this.name=name; |
this.name = name; |
||||||
this.sql=sql; |
this.sql = sql; |
||||||
} |
} |
||||||
/** |
|
||||||
* @return |
/** |
||||||
*/ |
* @return |
||||||
public String getName() { |
*/ |
||||||
return name; |
public String getName() { |
||||||
} |
return name; |
||||||
|
} |
||||||
/** |
|
||||||
* @return |
/** |
||||||
*/ |
* @return |
||||||
public String getSql() { |
*/ |
||||||
return sql; |
public String getSql() { |
||||||
} |
return sql; |
||||||
|
} |
||||||
/** |
|
||||||
* @param string |
/** |
||||||
*/ |
* @param string |
||||||
public void setName(String string) { |
*/ |
||||||
name = string; |
public void setName(String string) { |
||||||
} |
name = string; |
||||||
|
} |
||||||
/** |
|
||||||
* @param string |
/** |
||||||
*/ |
* @param string |
||||||
public void setSql(String string) { |
*/ |
||||||
sql = string; |
public void setSql(String string) { |
||||||
} |
sql = string; |
||||||
|
} |
||||||
} |
|
||||||
|
} |
||||||
|
|||||||
@ -1,127 +1,100 @@ |
|||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
import java.io.IOException; |
|
||||||
import java.sql.Connection; |
import java.io.IOException; |
||||||
import java.sql.DriverManager; |
import java.sql.Connection; |
||||||
import java.sql.SQLException; |
import java.sql.DriverManager; |
||||||
import java.util.Properties; |
import java.sql.SQLException; |
||||||
|
import java.util.Properties; |
||||||
import de.memtext.util.CryptUtils; |
|
||||||
import de.memtext.util.PropUtils; |
import de.memtext.util.CryptUtils; |
||||||
/** |
import de.memtext.util.PropUtils; |
||||||
* This class is a utility that makes the creation of database connections |
|
||||||
* easier. If necessary, one can use loadClass("jdbdcDriver-class") and then |
/** |
||||||
* use one of the static getConnection(..) methods |
* This class is a utility that makes the creation of database connections |
||||||
* @author MB |
* easier. If necessary, one can use loadClass("jdbdcDriver-class") and then |
||||||
* |
* use one of the static getConnection(..) methods |
||||||
|
* @author MB |
||||||
*/ |
* |
||||||
public class ConnectionCreator { |
|
||||||
public static void loadClass(String className) { |
*/ |
||||||
try { |
public class ConnectionCreator { |
||||||
Class.forName(className); |
public static void loadClass(String className) { |
||||||
|
try { |
||||||
} catch (Exception e) { |
Class.forName(className); |
||||||
System.out.println(e.toString()); |
|
||||||
System.exit(0); |
} catch (Exception e) { |
||||||
} |
System.out.println(e.toString()); |
||||||
} |
System.exit(0); |
||||||
public static Connection getConnection( |
} |
||||||
String url, |
} |
||||||
String username, |
|
||||||
String passwd) throws SQLException |
public static Connection getConnection(String url, String username, String passwd) throws SQLException { |
||||||
{ |
|
||||||
|
return DriverManager.getConnection(url, username, passwd); |
||||||
return DriverManager.getConnection(url, username, passwd); |
} |
||||||
} |
|
||||||
public static Connection getConnection( |
public static Connection getConnection(String driver, String url, String username, String passwd) throws SQLException, ClassNotFoundException { |
||||||
String driver, |
Class.forName(driver); |
||||||
String url, |
return getConnection(url, username, passwd); |
||||||
String username, |
} |
||||||
String passwd) |
|
||||||
throws SQLException, ClassNotFoundException { |
public static Connection getConnectionQuitOnException(String driver, String url, String username, String passwd) { |
||||||
Class.forName(driver); |
Connection con = null; |
||||||
return getConnection(url, username, passwd); |
try { |
||||||
} |
con = getConnection(driver, url, username, passwd); |
||||||
|
} catch (Exception e) { |
||||||
public static Connection getConnectionQuitOnException( |
System.out.println("Couldn't create connection to database " + url + "\n" + e.toString()); |
||||||
String driver, |
System.exit(-1); |
||||||
String url, |
} |
||||||
String username, |
return con; |
||||||
String passwd) { |
} |
||||||
Connection con = null; |
|
||||||
try { |
public static Connection getConnection(String propfilename, String driverkey, String urlkey, String usernamekey, String passwordkey) |
||||||
con = getConnection(driver, url, username, passwd); |
throws IOException, SQLException, ClassNotFoundException { |
||||||
} catch (Exception e) { |
Properties props = PropUtils.getProps(propfilename); |
||||||
System.out.println( |
String driver = PropUtils.getProperty(props, driverkey); |
||||||
"Couldn't create connection to database " |
String url = PropUtils.getProperty(props, urlkey); |
||||||
+ url |
String username = PropUtils.getProperty(props, usernamekey); |
||||||
+ "\n" |
String passwd = PropUtils.getProperty(props, passwordkey); |
||||||
+ e.toString()); |
return getConnection(driver, url, username, passwd); |
||||||
System.exit(-1); |
|
||||||
} |
} |
||||||
return con; |
|
||||||
} |
public static Connection getConnection(String propfilename) throws IOException, SQLException, ClassNotFoundException { |
||||||
public static Connection getConnection( |
return getConnection(propfilename, "driver", "url", "username", "password"); |
||||||
String propfilename, |
} |
||||||
String driverkey, |
|
||||||
String urlkey, |
/** |
||||||
String usernamekey, |
* Method getConnectionCryptPassword. |
||||||
String passwordkey) throws IOException, SQLException, ClassNotFoundException |
* 28.10.08 EInfache Verschlüsselungsmethode wird nicht mehr unterstützt |
||||||
{ |
* @param propfilename |
||||||
Properties props = PropUtils.getProps(propfilename); |
* @param string |
||||||
String driver = PropUtils.getProperty(props, driverkey); |
* @param string1 |
||||||
String url = PropUtils.getProperty(props, urlkey); |
* @param string11 |
||||||
String username = PropUtils.getProperty(props, usernamekey); |
* @param string111 |
||||||
String passwd = PropUtils.getProperty(props, passwordkey); |
* @return Connection |
||||||
return getConnection(driver, url, username, passwd); |
* @throws IOException |
||||||
|
* @throws ClassNotFoundException |
||||||
} |
* @throws SQLException |
||||||
public static Connection getConnection(String propfilename) throws IOException, SQLException, ClassNotFoundException |
*/ |
||||||
{ |
public static Connection getConnectionCryptPassword(String propfilename, String driverkey, String urlkey, String usernamekey, String passwordkey) |
||||||
return getConnection( |
throws IOException, SQLException, ClassNotFoundException { |
||||||
propfilename, |
Properties props = PropUtils.getProps(propfilename); |
||||||
"driver", |
String driver = PropUtils.getProperty(props, driverkey); |
||||||
"url", |
String url = PropUtils.getProperty(props, urlkey); |
||||||
"username", |
String username = PropUtils.getProperty(props, usernamekey); |
||||||
"password"); |
String passwd = PropUtils.getProperty(props, passwordkey); |
||||||
} |
if (passwd.startsWith("sx_des")) { |
||||||
|
try { |
||||||
/** |
passwd = CryptUtils.decryptStringDES(passwd.substring(6)); |
||||||
* Method getConnectionCryptPassword. |
} catch (Exception e) { |
||||||
* 28.10.08 EInfache Verschlüsselungsmethode wird nicht mehr unterstützt |
e.printStackTrace(); |
||||||
* @param propfilename |
throw new SQLException("DES-Passwort konnte nicht entschlüsselt werden"); |
||||||
* @param string |
} |
||||||
* @param string1 |
} |
||||||
* @param string11 |
// else
|
||||||
* @param string111 |
// passwd=de.memtext.util.CryptUtils.decryptSimple(passwd );
|
||||||
* @return Connection |
return getConnection(driver, url, username, passwd); |
||||||
* @throws IOException |
} |
||||||
* @throws ClassNotFoundException |
|
||||||
* @throws SQLException |
} |
||||||
*/ |
|
||||||
public static Connection getConnectionCryptPassword( |
|
||||||
String propfilename, |
|
||||||
String driverkey, |
|
||||||
String urlkey, |
|
||||||
String usernamekey, |
|
||||||
String passwordkey) throws IOException, SQLException, ClassNotFoundException |
|
||||||
{ |
|
||||||
Properties props = PropUtils.getProps(propfilename); |
|
||||||
String driver = PropUtils.getProperty(props, driverkey); |
|
||||||
String url = PropUtils.getProperty(props, urlkey); |
|
||||||
String username = PropUtils.getProperty(props, usernamekey); |
|
||||||
String passwd =PropUtils.getProperty(props, passwordkey); |
|
||||||
if (passwd.startsWith("sx_des")) { |
|
||||||
try { |
|
||||||
passwd = CryptUtils.decryptStringDES(passwd.substring(6)); |
|
||||||
} catch (Exception e) { |
|
||||||
e.printStackTrace(); |
|
||||||
throw new SQLException("DES-Passwort konnte nicht entschlüsselt werden"); |
|
||||||
} |
|
||||||
} |
|
||||||
// else
|
|
||||||
// passwd=de.memtext.util.CryptUtils.decryptSimple(passwd );
|
|
||||||
return getConnection(driver, url, username, passwd); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|||||||
@ -1,37 +1,43 @@ |
|||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import de.memtext.baseobjects.NamedObject; |
import de.memtext.baseobjects.NamedObject; |
||||||
/** |
|
||||||
* This class represents a Database system like Informix or Postgres |
/** |
||||||
*/ |
* This class represents a Database system like Informix or Postgres |
||||||
public class DB extends NamedObject { |
*/ |
||||||
private String version; |
public class DB extends NamedObject { |
||||||
static public final DB INFORMIX = new DB("Informix", "7.3"); |
private String version; |
||||||
static public final DB POSTGRES = new DB("Postgres", "7.3"); |
|
||||||
static public final DB ACCESS = new DB("Access", "2000"); |
static public final DB INFORMIX = new DB("Informix", "7.3"); |
||||||
/** |
|
||||||
* The public constructors are needed because the DB class is |
static public final DB POSTGRES = new DB("Postgres", "7.3"); |
||||||
* a java bean which is cool for XMLEncoding |
|
||||||
* |
static public final DB ACCESS = new DB("Access", "2000"); |
||||||
*/ |
|
||||||
public DB() { |
/** |
||||||
this("Unbekannte Datenbank",""); |
* The public constructors are needed because the DB class is |
||||||
} |
* a java bean which is cool for XMLEncoding |
||||||
public DB(String name) { |
* |
||||||
this(name, ""); |
*/ |
||||||
} |
public DB() { |
||||||
|
this("Unbekannte Datenbank", ""); |
||||||
public DB(String name, String version) { |
} |
||||||
super(name); |
|
||||||
this.version = version; |
public DB(String name) { |
||||||
} |
this(name, ""); |
||||||
|
} |
||||||
public boolean equals(Object o) { |
|
||||||
if (!(o instanceof DB)) |
public DB(String name, String version) { |
||||||
return false; |
super(name); |
||||||
DB db = (DB) o; |
this.version = version; |
||||||
return this.getName().equals(db.getName()); |
} |
||||||
} |
|
||||||
} |
@Override |
||||||
|
public boolean equals(Object o) { |
||||||
|
if (!(o instanceof DB)) return false; |
||||||
|
DB db = (DB) o; |
||||||
|
return this.getName().equals(db.getName()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
//Created on 03.12.2003 at 15:54:27
|
//Created on 03.12.2003 at 15:54:27
|
||||||
File diff suppressed because it is too large
Load Diff
@ -1,104 +1,78 @@ |
|||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import java.sql.DriverManager; |
import java.sql.DriverManager; |
||||||
import java.sql.SQLException; |
import java.sql.SQLException; |
||||||
import java.util.Iterator; |
import java.util.Iterator; |
||||||
import java.util.List; |
import java.util.List; |
||||||
|
|
||||||
import de.memtext.util.StringUtils; |
import de.memtext.util.StringUtils; |
||||||
|
|
||||||
public class DBComparison { |
public class DBComparison { |
||||||
|
|
||||||
private DBComparison() { |
private DBComparison() { |
||||||
super(); |
super(); |
||||||
} |
} |
||||||
public static void main(String a[]) { |
|
||||||
try { |
public static void main(String a[]) { |
||||||
Class.forName("org.hsqldb.jdbcDriver"); |
try { |
||||||
|
Class.forName("org.hsqldb.jdbcDriver"); |
||||||
java.sql.Connection con = |
|
||||||
DriverManager.getConnection( |
java.sql.Connection con = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost:9000", "sa", ""); |
||||||
"jdbc:hsqldb:hsql://localhost:9000", |
DBAccess.addConnection("ssc", con); |
||||||
"sa", |
java.sql.Connection con2 = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost:9500", "sa", ""); |
||||||
""); |
DBAccess.addConnection("ssc-test", con2); |
||||||
DBAccess.addConnection("ssc", con); |
compare("ssc", "ssc-test"); |
||||||
java.sql.Connection con2 = |
|
||||||
DriverManager.getConnection( |
} catch (ClassNotFoundException e) { |
||||||
"jdbc:hsqldb:hsql://localhost:9500", |
e.printStackTrace(); |
||||||
"sa", |
} catch (SQLException e) { |
||||||
""); |
e.printStackTrace(); |
||||||
DBAccess.addConnection("ssc-test", con2); |
} catch (Exception e) { |
||||||
compare("ssc", "ssc-test"); |
e.printStackTrace(); |
||||||
|
} |
||||||
} catch (ClassNotFoundException e) { |
|
||||||
e.printStackTrace(); |
} |
||||||
} catch (SQLException e) { |
|
||||||
e.printStackTrace(); |
private static void compare(String db1, String db2) throws SQLException { |
||||||
} catch (Exception e) { |
System.out.println("Start comparing..."); |
||||||
e.printStackTrace(); |
StringBuffer fineTables = new StringBuffer("The following tables are fine: "); |
||||||
} |
List tableList = DBAccess.get(db1).getTableList(); |
||||||
|
boolean isOk = false; |
||||||
} |
for (Iterator it = tableList.iterator(); it.hasNext();) { |
||||||
private static void compare(String db1, String db2) { |
String table = (String) it.next(); |
||||||
System.out.println("Start comparing..."); |
|
||||||
StringBuffer fineTables = |
if (DBAccess.get(db2).hasTable(table)) { |
||||||
new StringBuffer("The following tables are fine: "); |
isOk = true; |
||||||
List tableList = DBAccess.get(db1).getTableList(); |
if (DBAccess.get(db1).getColumnCount(table) != DBAccess.get(db2).getColumnCount(table)) { |
||||||
boolean isOk = false; |
System.out.println("Table " + table + " has a different number of columns"); |
||||||
for (Iterator it = tableList.iterator(); it.hasNext();) { |
isOk = false; |
||||||
String table = (String) it.next(); |
} else { |
||||||
|
List colList = DBAccess.get(db1).getColumnNames(table); |
||||||
if (DBAccess.get(db2).hasTable(table)) { |
for (Iterator it2 = colList.iterator(); it2.hasNext();) { |
||||||
isOk = true; |
String colname = (String) it2.next(); |
||||||
if (DBAccess.get(db1).getColumnCount(table) |
if (!DBAccess.get(db2).hasColumn(table, colname)) { |
||||||
!= DBAccess.get(db2).getColumnCount(table)) { |
System.out.println("Table " + table + " in " + db2 + " doesn't have column:" + colname); |
||||||
System.out.println( |
isOk = false; |
||||||
"Table " |
} else { |
||||||
+ table |
|
||||||
+ " has a different number of columns"); |
if (DBAccess.get(db1).getColumnType(table, colname) != DBAccess.get(db2).getColumnType(table, colname)) { |
||||||
isOk = false; |
System.out.println("Table " + table + " column:" + colname + " are of different types"); |
||||||
} else { |
isOk = false; |
||||||
List colList = DBAccess.get(db1).getColumnNames(table); |
} |
||||||
for (Iterator it2 = colList.iterator(); it2.hasNext();) { |
|
||||||
String colname = (String) it2.next(); |
} |
||||||
if (!DBAccess.get(db2).hasColumn(table, colname)) { |
} |
||||||
System.out.println( |
if (isOk) fineTables.append(table + ","); |
||||||
"Table " |
} |
||||||
+ table |
|
||||||
+ " in " |
} else { |
||||||
+ db2 |
System.out.println(db2 + " doesn't contain table:" + table); |
||||||
+ " doesn't have column:" |
} |
||||||
+ colname); |
} |
||||||
isOk = false; |
StringUtils.deleteLastChar(fineTables); |
||||||
} else { |
System.out.println(fineTables); |
||||||
|
System.out.println("..done"); |
||||||
if (DBAccess.get(db1).getColumnType(table, colname) |
} |
||||||
!= DBAccess.get(db2).getColumnType( |
} |
||||||
table, |
|
||||||
colname)) { |
|
||||||
System.out.println( |
|
||||||
"Table " |
|
||||||
+ table |
|
||||||
+ " column:" |
|
||||||
+ colname |
|
||||||
+ " are of different types"); |
|
||||||
isOk = false; |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
} |
|
||||||
if (isOk) |
|
||||||
fineTables.append(table + ","); |
|
||||||
} |
|
||||||
|
|
||||||
} else { |
|
||||||
System.out.println(db2 + " doesn't contain table:" + table); |
|
||||||
} |
|
||||||
} |
|
||||||
StringUtils.deleteLastChar(fineTables); |
|
||||||
System.out.println(fineTables); |
|
||||||
System.out.println("..done"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
//Created on 11.02.2004 at 13:19:36
|
//Created on 11.02.2004 at 13:19:36
|
||||||
@ -1,20 +1,19 @@ |
|||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
/** |
/** |
||||||
* Eine spezielle Exception im Servlet. |
* Eine spezielle Exception im Servlet. |
||||||
* Wird zwar im Applet eigentlich nicht gebraucht, aber trotzdem |
* Wird zwar im Applet eigentlich nicht gebraucht, aber trotzdem |
||||||
* in diesem Package, damit Klassen wie Sicht einheitliche throws-Deklarationen haben. |
* in diesem Package, damit Klassen wie Sicht einheitliche throws-Deklarationen haben. |
||||||
* |
* |
||||||
* @author Marlies Winterstein |
* @author Marlies Winterstein |
||||||
* @version 2.0, 18.2.2002 |
* @version 2.0, 18.2.2002 |
||||||
*/ |
*/ |
||||||
public class DBServletException extends Exception |
public class DBServletException extends Exception { |
||||||
{ |
public DBServletException() { |
||||||
public DBServletException() |
super(); |
||||||
{ |
} |
||||||
super(); |
|
||||||
} |
public DBServletException(String msg) { |
||||||
public DBServletException(String msg) |
super(msg); |
||||||
{ |
} |
||||||
super(msg); |
} |
||||||
} |
|
||||||
} |
|
||||||
|
|||||||
@ -1,96 +1,63 @@ |
|||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import java.sql.Connection; |
import java.sql.Connection; |
||||||
import java.sql.Statement; |
import java.sql.Statement; |
||||||
|
|
||||||
import de.memtext.util.TimeUtils; |
import de.memtext.util.TimeUtils; |
||||||
|
|
||||||
public class DBTimer { |
public class DBTimer { |
||||||
private static int runCount=200; |
private static int runCount = 200; |
||||||
private static boolean logEachRun=false; |
|
||||||
//private static String driver="org.hsqldb.jdbcDriver";
|
private static boolean logEachRun = false; |
||||||
private static String driver="com.informix.jdbc.IfxDriver"; |
|
||||||
//private static String url="jdbc:hsqldb:hsql://localhost:9001";
|
//private static String driver="org.hsqldb.jdbcDriver";
|
||||||
private static String url="jdbc:informix-sqli://jupiter:50000:informixserver=superx_host;database=superx"; |
private static String driver = "com.informix.jdbc.IfxDriver"; |
||||||
private static String user="superx"; |
|
||||||
private static String passwd="anfang12"; |
//private static String url="jdbc:hsqldb:hsql://localhost:9001";
|
||||||
private static String sql="execute procedure sp_cob_keychild('1',0);"; |
private static String url = "jdbc:informix-sqli://jupiter:50000:informixserver=superx_host;database=superx"; |
||||||
|
|
||||||
//wenn ein zweiter Sql folgen soll - drop table tmp_xx muss z.B. in eigenem Aufruf sein.
|
private static String user = "superx"; |
||||||
private static String sql2=null;//"select sum(betrag) from cob_busa,tmp_children T where fikrkey=T.key";
|
|
||||||
//"select sum(betrag) from cob_busa where fikrkey in (select key from tmp_children)";
|
private static String passwd = "anfang12"; |
||||||
private static String sql3=null;//"drop table tmp_children;";
|
|
||||||
public static void main(String[] args) { |
private static String sql = "execute procedure sp_cob_keychild('1',0);"; |
||||||
//sql="select sum(betrag) from cob_busa C, tmp_children T where fikrkey=T.key and T.parent='1'";
|
|
||||||
sql = "select sum(betrag) from cob_busa where fikrkey in ('1', \n" + |
//wenn ein zweiter Sql folgen soll - drop table tmp_xx muss z.B. in eigenem Aufruf sein.
|
||||||
" '11 ', \n" + |
private static String sql2 = null;//"select sum(betrag) from cob_busa,tmp_children T where fikrkey=T.key";
|
||||||
" '111 ', \n" + |
//"select sum(betrag) from cob_busa where fikrkey in (select key from tmp_children)";
|
||||||
" '1111 ', \n" + |
|
||||||
" '1112 ', \n" + |
private static String sql3 = null;//"drop table tmp_children;";
|
||||||
" '112 ', \n" + |
|
||||||
" '1121 ', \n" + |
public static void main(String[] args) { |
||||||
" '1122 ', \n" + |
//sql="select sum(betrag) from cob_busa C, tmp_children T where fikrkey=T.key and T.parent='1'";
|
||||||
" '113 ', \n" + |
sql = "select sum(betrag) from cob_busa where fikrkey in ('1', \n" + " '11 ', \n" + " '111 ', \n" + " '1111 ', \n" + " '1112 ', \n" + " '112 ', \n" |
||||||
" '1131 ', \n" + |
+ " '1121 ', \n" + " '1122 ', \n" + " '113 ', \n" + " '1131 ', \n" + " '1132 ', \n" + " '12 ', \n" + " '121 ', \n" + " '1211 ', \n" |
||||||
" '1132 ', \n" + |
+ " '1212 ', \n" + " '1213 ', \n" + " '122 ', \n" + " '123 ', \n" + " '124 ', \n" + " '125 ', \n" + " '126 ', \n" + " '13 ', \n" |
||||||
" '12 ', \n" + |
+ " '131 ', \n" + " '1311 ', \n" + " '1312 ', \n" + " '1313 ', \n" + " '132 ', \n" + " '1321 ', \n" + " '1322 ', \n" + " '1323 ', \n" |
||||||
" '121 ', \n" + |
+ " '133 ', \n" + " '1331 ', \n" + " '1332 ', \n" + " '1333 ', \n" + " '1334 ', \n" + " '134 ', \n" + " '135 ', \n" + " '136 ', \n" |
||||||
" '1211 ', \n" + |
+ " '137 ', \n" + " '138 ')"; |
||||||
" '1212 ', \n" + |
try { |
||||||
" '1213 ', \n" + |
Class.forName(driver); |
||||||
" '122 ', \n" + |
Connection conn = java.sql.DriverManager.getConnection(url, user, passwd); |
||||||
" '123 ', \n" + |
Statement stmt = conn.createStatement(); |
||||||
" '124 ', \n" + |
TimeUtils t = new TimeUtils(); |
||||||
" '125 ', \n" + |
System.out.println("start " + sql); |
||||||
" '126 ', \n" + |
for (int i = 1; i <= runCount; i++) { |
||||||
" '13 ', \n" + |
if (logEachRun) System.out.println(i); |
||||||
" '131 ', \n" + |
stmt.execute(sql); |
||||||
" '1311 ', \n" + |
if (sql2 != null) stmt.execute(sql2); |
||||||
" '1312 ', \n" + |
if (sql3 != null) stmt.execute(sql3); |
||||||
" '1313 ', \n" + |
} |
||||||
" '132 ', \n" + |
t.print(runCount + " times"); |
||||||
" '1321 ', \n" + |
stmt.close(); |
||||||
" '1322 ', \n" + |
conn.close(); |
||||||
" '1323 ', \n" + |
System.out.println("done"); |
||||||
" '133 ', \n" + |
|
||||||
" '1331 ', \n" + |
} catch (Exception e) { |
||||||
" '1332 ', \n" + |
e.printStackTrace(); |
||||||
" '1333 ', \n" + |
System.exit(-1); |
||||||
" '1334 ', \n" + |
} |
||||||
" '134 ', \n" + |
} |
||||||
" '135 ', \n" + |
} |
||||||
" '136 ', \n" + |
|
||||||
" '137 ', \n" + |
|
||||||
" '138 ')"; |
|
||||||
try { |
|
||||||
Class.forName(driver); |
|
||||||
Connection conn = |
|
||||||
java.sql.DriverManager.getConnection( |
|
||||||
url, |
|
||||||
user, |
|
||||||
passwd); |
|
||||||
Statement stmt = conn.createStatement(); |
|
||||||
TimeUtils t=new TimeUtils(); |
|
||||||
System.out.println("start "+sql); |
|
||||||
for (int i=1;i<=runCount;i++) |
|
||||||
{ |
|
||||||
if (logEachRun) System.out.println(i); |
|
||||||
stmt.execute(sql); |
|
||||||
if (sql2!=null) |
|
||||||
stmt.execute(sql2); |
|
||||||
if (sql3!=null) |
|
||||||
stmt.execute(sql3); |
|
||||||
} |
|
||||||
t.print(runCount+" times"); |
|
||||||
stmt.close(); |
|
||||||
conn.close(); |
|
||||||
System.out.println("done"); |
|
||||||
|
|
||||||
} catch (Exception e) { |
|
||||||
e.printStackTrace(); |
|
||||||
System.exit(-1); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
//Created on 09.03.2005 at 10:05:37
|
//Created on 09.03.2005 at 10:05:37
|
||||||
@ -1,106 +1,109 @@ |
|||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import java.sql.Connection; |
import java.sql.Connection; |
||||||
import java.sql.DriverManager; |
import java.sql.DriverManager; |
||||||
import java.sql.SQLException; |
import java.sql.SQLException; |
||||||
|
|
||||||
import de.memtext.baseobjects.NamedObject; |
import de.memtext.baseobjects.NamedObject; |
||||||
import de.memtext.util.CryptUtils; |
|
||||||
/** |
/** |
||||||
* wonder what this is |
* wonder what this is |
||||||
*/ |
*/ |
||||||
public class DataSource extends NamedObject { |
public class DataSource extends NamedObject { |
||||||
|
|
||||||
private static final String CRYPT_PREFIX = "^^@@@"; |
private static final String CRYPT_PREFIX = "^^@@@"; |
||||||
private String url, username, cryptPassword, driver; |
|
||||||
private transient String password; |
private String url, username, cryptPassword, driver; |
||||||
private DB db; |
|
||||||
public DataSource() { |
private transient String password; |
||||||
} |
|
||||||
|
private DB db; |
||||||
public DataSource(String url, String username, String password) { |
|
||||||
setUrl(url); |
public DataSource() { |
||||||
setUsername(username); |
} |
||||||
setPassword(password); |
|
||||||
} |
public DataSource(String url, String username, String password) { |
||||||
|
setUrl(url); |
||||||
public void setInformixSampleValues() { |
setUsername(username); |
||||||
setUrl("jupiter:50000:informixserver=superx_host;database=superx"); |
setPassword(password); |
||||||
setUsername("informix"); |
} |
||||||
setPassword(""); |
|
||||||
this.db=DB.INFORMIX; |
public void setInformixSampleValues() { |
||||||
} |
setUrl("jupiter:50000:informixserver=superx_host;database=superx"); |
||||||
public void setAccessSampleValues() { |
setUsername("informix"); |
||||||
setUrl("jdbc:odbc:jdbcodbc:"); |
setPassword(""); |
||||||
setUsername("informix"); |
this.db = DB.INFORMIX; |
||||||
setPassword(""); |
} |
||||||
this.db=DB.ACCESS; |
|
||||||
} |
public void setAccessSampleValues() { |
||||||
|
setUrl("jdbc:odbc:jdbcodbc:"); |
||||||
public String getDriver() { |
setUsername("informix"); |
||||||
return driver; |
setPassword(""); |
||||||
} |
this.db = DB.ACCESS; |
||||||
|
} |
||||||
public String getPassword() { |
|
||||||
return password; |
public String getDriver() { |
||||||
} |
return driver; |
||||||
|
} |
||||||
public String getUrl() { |
|
||||||
return url; |
public String getPassword() { |
||||||
} |
return password; |
||||||
|
} |
||||||
public String getUsername() { |
|
||||||
return username; |
public String getUrl() { |
||||||
} |
return url; |
||||||
|
} |
||||||
public void setDriver(String string) { |
|
||||||
driver = string; |
public String getUsername() { |
||||||
} |
return username; |
||||||
|
} |
||||||
public void setPassword(String string) { |
|
||||||
password = string; |
public void setDriver(String string) { |
||||||
this.setCryptPassword(string); |
driver = string; |
||||||
} |
} |
||||||
|
|
||||||
public void setUrl(String string) { |
public void setPassword(String string) { |
||||||
url = string; |
password = string; |
||||||
} |
this.setCryptPassword(string); |
||||||
|
} |
||||||
public void setUsername(String string) { |
|
||||||
username = string; |
public void setUrl(String string) { |
||||||
} |
url = string; |
||||||
|
} |
||||||
public DB getDb() { |
|
||||||
return db; |
public void setUsername(String string) { |
||||||
} |
username = string; |
||||||
|
} |
||||||
public void setDb(DB db) { |
|
||||||
this.db = db; |
public DB getDb() { |
||||||
} |
return db; |
||||||
|
} |
||||||
public void testConnection() throws SQLException, ClassNotFoundException { |
|
||||||
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); |
public void setDb(DB db) { |
||||||
Connection con=DriverManager.getConnection(url,username,password); |
this.db = db; |
||||||
con.close(); |
} |
||||||
|
|
||||||
|
public void testConnection() throws SQLException, ClassNotFoundException { |
||||||
} |
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); |
||||||
|
Connection con = DriverManager.getConnection(url, username, password); |
||||||
public String getCryptPassword() { |
con.close(); |
||||||
return cryptPassword; |
|
||||||
} |
|
||||||
|
} |
||||||
public void setCryptPassword(String aPwd) { |
|
||||||
if (!isEncrypted(aPwd)) |
public String getCryptPassword() { |
||||||
{ |
return cryptPassword; |
||||||
//cryptPassword =CRYPT_PREFIX + CryptUtils.encryptStringDES(aPwd);
|
} |
||||||
} |
|
||||||
} |
public void setCryptPassword(String aPwd) { |
||||||
|
if (!isEncrypted(aPwd)) { |
||||||
public boolean isEncrypted(String aPwd) |
//cryptPassword =CRYPT_PREFIX + CryptUtils.encryptStringDES(aPwd);
|
||||||
{ |
} |
||||||
return aPwd.startsWith(CRYPT_PREFIX); |
} |
||||||
} |
|
||||||
} |
public boolean isEncrypted(String aPwd) { |
||||||
|
return aPwd.startsWith(CRYPT_PREFIX); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
//Created on 17.04.2004 at 16:28:15
|
//Created on 17.04.2004 at 16:28:15
|
||||||
@ -1,116 +1,121 @@ |
|||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import java.awt.event.ActionEvent; |
import java.awt.event.ActionEvent; |
||||||
import java.awt.event.ActionListener; |
import java.awt.event.ActionListener; |
||||||
import java.sql.SQLException; |
import java.sql.SQLException; |
||||||
|
|
||||||
import javax.swing.JButton; |
import javax.swing.JButton; |
||||||
import javax.swing.JPanel; |
import javax.swing.JPanel; |
||||||
|
|
||||||
import de.memtext.observ.DocumentListenerObserver; |
import de.memtext.observ.DocumentListenerObserver; |
||||||
import de.memtext.widgets.InfoMessage; |
import de.memtext.widgets.InfoMessage; |
||||||
import de.memtext.widgets.LabeledPasswordField; |
import de.memtext.widgets.LabeledPasswordField; |
||||||
import de.memtext.widgets.LabeledTextField; |
import de.memtext.widgets.LabeledTextField; |
||||||
import de.memtext.widgets.MultilineEditPanel; |
import de.memtext.widgets.MultilineEditPanel; |
||||||
import de.memtext.widgets.WarningMessage; |
import de.memtext.widgets.WarningMessage; |
||||||
|
|
||||||
public class DataSourceEditPanel extends MultilineEditPanel { |
public class DataSourceEditPanel extends MultilineEditPanel { |
||||||
private DataSource ds; |
private DataSource ds; |
||||||
private LabeledTextField hostField = new LabeledTextField("Host", 10); |
|
||||||
private LabeledTextField serverField = new LabeledTextField("Server", 10); |
private LabeledTextField hostField = new LabeledTextField("Host", 10); |
||||||
private LabeledTextField serviceField = new LabeledTextField("Service", 10); |
|
||||||
private LabeledTextField odbcSourceField = |
private LabeledTextField serverField = new LabeledTextField("Server", 10); |
||||||
new LabeledTextField("Odbc-DSN", 10); |
|
||||||
private LabeledTextField usernameField = |
private LabeledTextField serviceField = new LabeledTextField("Service", 10); |
||||||
new LabeledTextField("Kennung", 10); |
|
||||||
private LabeledTextField passwordField = |
private LabeledTextField odbcSourceField = new LabeledTextField("Odbc-DSN", 10); |
||||||
new LabeledPasswordField("Password", 10); |
|
||||||
private JPanel pButtons = new JPanel(); |
private LabeledTextField usernameField = new LabeledTextField("Kennung", 10); |
||||||
|
|
||||||
public DataSourceEditPanel() { |
private LabeledTextField passwordField = new LabeledPasswordField("Password", 10); |
||||||
this.setBackground(null); |
|
||||||
odbcSourceField.setValue("sospos"); |
private JPanel pButtons = new JPanel(); |
||||||
odbcSourceField.setBackground(null); |
|
||||||
usernameField.setValue("admin"); |
public DataSourceEditPanel() { |
||||||
this.add(hostField); |
this.setBackground(null); |
||||||
this.add(serverField); |
odbcSourceField.setValue("sospos"); |
||||||
this.add(serviceField); |
odbcSourceField.setBackground(null); |
||||||
this.add(odbcSourceField); |
usernameField.setValue("admin"); |
||||||
|
this.add(hostField); |
||||||
this.add(usernameField); |
this.add(serverField); |
||||||
|
this.add(serviceField); |
||||||
this.add(passwordField); |
this.add(odbcSourceField); |
||||||
//this.addGlue();
|
|
||||||
JButton btnTesten = new JButton("testen"); |
this.add(usernameField); |
||||||
btnTesten.setBackground(null); |
|
||||||
pButtons.setBackground(null); |
this.add(passwordField); |
||||||
btnTesten.addActionListener(new ActionListener() { |
//this.addGlue();
|
||||||
public void actionPerformed(ActionEvent ae) { |
JButton btnTesten = new JButton("testen"); |
||||||
test(); |
btnTesten.setBackground(null); |
||||||
} |
pButtons.setBackground(null); |
||||||
}); |
btnTesten.addActionListener(new ActionListener() { |
||||||
pButtons.add(btnTesten); |
|
||||||
//this.addGlue();
|
@Override |
||||||
this.add(pButtons); |
public void actionPerformed(ActionEvent ae) { |
||||||
} |
test(); |
||||||
public void setDataSource(DataSource ds) { |
} |
||||||
this.ds = ds; |
}); |
||||||
setMode(ds.getDb()); |
pButtons.add(btnTesten); |
||||||
} |
//this.addGlue();
|
||||||
public void addButton(JButton btn) { |
this.add(pButtons); |
||||||
pButtons.add(btn); |
} |
||||||
} |
|
||||||
private void setMode(DB db) { |
public void setDataSource(DataSource ds) { |
||||||
if (db.equals(DB.ACCESS)) { |
this.ds = ds; |
||||||
odbcSourceField.setVisible(true); |
setMode(ds.getDb()); |
||||||
hostField.setVisible(false); |
} |
||||||
serverField.setVisible(false); |
|
||||||
serviceField.setVisible(false); |
public void addButton(JButton btn) { |
||||||
} |
pButtons.add(btn); |
||||||
if (db.equals(DB.INFORMIX)) { |
} |
||||||
odbcSourceField.setVisible(false); |
|
||||||
hostField.setVisible(true); |
private void setMode(DB db) { |
||||||
serverField.setVisible(true); |
if (db.equals(DB.ACCESS)) { |
||||||
serviceField.setVisible(true); |
odbcSourceField.setVisible(true); |
||||||
} |
hostField.setVisible(false); |
||||||
} |
serverField.setVisible(false); |
||||||
protected void test() { |
serviceField.setVisible(false); |
||||||
updateDataSource(); |
} |
||||||
try { |
if (db.equals(DB.INFORMIX)) { |
||||||
ds.testConnection(); |
odbcSourceField.setVisible(false); |
||||||
InfoMessage.show(this, "Verbindung erfolgreich aufgebaut", "Erfolg"); |
hostField.setVisible(true); |
||||||
} catch (SQLException e) { |
serverField.setVisible(true); |
||||||
if (ds.getDb().equals( DB.ACCESS)) { |
serviceField.setVisible(true); |
||||||
WarningMessage.show(this, |
} |
||||||
"Verbindung zur ODBC-Quelle " |
} |
||||||
+ odbcSourceField.getValue() |
|
||||||
+ " konnte nicht aufgebaut werden.\n" |
protected void test() { |
||||||
+ e, |
updateDataSource(); |
||||||
"Achtung"); |
try { |
||||||
} |
ds.testConnection(); |
||||||
} catch (ClassNotFoundException e) { |
InfoMessage.show(this, "Verbindung erfolgreich aufgebaut", "Erfolg"); |
||||||
WarningMessage.show(this, |
} catch (SQLException e) { |
||||||
"Benötigte Treiber-Klase nicht gefunden ", |
if (ds.getDb().equals(DB.ACCESS)) { |
||||||
"Achtung"); |
WarningMessage.show(this, "Verbindung zur ODBC-Quelle " + odbcSourceField.getValue() + " konnte nicht aufgebaut werden.\n" + e, "Achtung"); |
||||||
} |
} |
||||||
} |
} catch (ClassNotFoundException e) { |
||||||
public void updateDataSource() { |
WarningMessage.show(this, "Benötigte Treiber-Klase nicht gefunden ", "Achtung"); |
||||||
if (ds.getDb() == DB.ACCESS) { |
} |
||||||
ds.setUrl("jdbc:odbc:" + odbcSourceField.getValue()); |
} |
||||||
} |
|
||||||
ds.setUsername(usernameField.getValue().toString()); |
public void updateDataSource() { |
||||||
ds.setPassword(""); |
if (ds.getDb() == DB.ACCESS) { |
||||||
} |
ds.setUrl("jdbc:odbc:" + odbcSourceField.getValue()); |
||||||
public void addDocumentListener(DocumentListenerObserver listener) { |
} |
||||||
hostField.addDocumentListener(listener); |
ds.setUsername(usernameField.getValue().toString()); |
||||||
serverField.addDocumentListener(listener); |
ds.setPassword(""); |
||||||
serviceField.addDocumentListener(listener); |
} |
||||||
odbcSourceField.addDocumentListener(listener); |
|
||||||
|
public void addDocumentListener(DocumentListenerObserver listener) { |
||||||
usernameField.addDocumentListener(listener); |
hostField.addDocumentListener(listener); |
||||||
|
serverField.addDocumentListener(listener); |
||||||
passwordField.addDocumentListener(listener); |
serviceField.addDocumentListener(listener); |
||||||
} |
odbcSourceField.addDocumentListener(listener); |
||||||
} |
|
||||||
|
usernameField.addDocumentListener(listener); |
||||||
|
|
||||||
|
passwordField.addDocumentListener(listener); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
//Created on 17.04.2004 at 16:37:44
|
//Created on 17.04.2004 at 16:37:44
|
||||||
@ -1,94 +1,92 @@ |
|||||||
/* |
/* |
||||||
* Created on 21.06.2003 |
* Created on 21.06.2003 |
||||||
* |
* |
||||||
* To change the template for this generated file go to |
* To change the template for this generated file go to |
||||||
* Window>Preferences>Java>Code Generation>Code and Comments |
* Window>Preferences>Java>Code Generation>Code and Comments |
||||||
*/ |
*/ |
||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
/** |
/** |
||||||
* @author MB |
* @author MB |
||||||
* |
* |
||||||
* To change the template for this generated type comment go to |
* To change the template for this generated type comment go to |
||||||
* Window>Preferences>Java>Code Generation>Code and Comments |
* Window>Preferences>Java>Code Generation>Code and Comments |
||||||
*/ |
*/ |
||||||
public class DbRequest |
public class DbRequest |
||||||
|
|
||||||
implements java.io.Serializable { |
implements java.io.Serializable { |
||||||
static final long serialVersionUID = -2L; |
static final long serialVersionUID = -2L; |
||||||
|
|
||||||
|
|
||||||
private String sql; |
private String sql; |
||||||
private String name; |
|
||||||
private Object[] params; |
private String name; |
||||||
private int type; |
|
||||||
private DbRequestType dbRequestType; |
private Object[] params; |
||||||
public DbRequest(String sql) |
|
||||||
{ |
private int type; |
||||||
this(null,sql,null,null); |
|
||||||
} |
private DbRequestType dbRequestType; |
||||||
public DbRequest(String name,String sql,Object[] params) |
|
||||||
{ |
public DbRequest(String sql) { |
||||||
this(name,sql,params,null); |
this(null, sql, null, null); |
||||||
} |
} |
||||||
/** |
|
||||||
* Request type used by servlet |
public DbRequest(String name, String sql, Object[] params) { |
||||||
* @param name |
this(name, sql, params, null); |
||||||
* @param sql |
} |
||||||
* @param params |
|
||||||
* @param dbRequestType |
/** |
||||||
*/ |
* Request type used by servlet |
||||||
public DbRequest(String name,String sql,Object[] params,DbRequestType dbRequestType) |
* @param name |
||||||
{ |
* @param sql |
||||||
setName(name); |
* @param params |
||||||
setSql(sql); |
* @param dbRequestType |
||||||
setParams(params); |
*/ |
||||||
this.dbRequestType=dbRequestType; |
public DbRequest(String name, String sql, Object[] params, DbRequestType dbRequestType) { |
||||||
} |
setName(name); |
||||||
|
setSql(sql); |
||||||
public String getName() |
setParams(params); |
||||||
{ |
this.dbRequestType = dbRequestType; |
||||||
return name; |
} |
||||||
} |
|
||||||
|
public String getName() { |
||||||
public void setName(String name) |
return name; |
||||||
{ |
} |
||||||
this.name=name; |
|
||||||
} |
public void setName(String name) { |
||||||
|
this.name = name; |
||||||
public Object[] getParams() |
} |
||||||
{ |
|
||||||
return params; |
public Object[] getParams() { |
||||||
} |
return params; |
||||||
|
} |
||||||
public void setParams(Object[] params) |
|
||||||
{ |
public void setParams(Object[] params) { |
||||||
this.params=params; |
this.params = params; |
||||||
} |
} |
||||||
|
|
||||||
public String getSql() |
public String getSql() { |
||||||
{ |
return sql; |
||||||
return sql; |
} |
||||||
} |
|
||||||
|
public void setSql(String sql) { |
||||||
public void setSql(String sql) |
this.sql = sql; |
||||||
{ |
} |
||||||
this.sql=sql; |
|
||||||
} |
/** |
||||||
|
* @return |
||||||
/** |
*/ |
||||||
* @return |
public DbRequestType getDbRequestType() { |
||||||
*/ |
return dbRequestType; |
||||||
public DbRequestType getDbRequestType() { |
} |
||||||
return dbRequestType; |
|
||||||
} |
/** |
||||||
|
* @param type |
||||||
/** |
*/ |
||||||
* @param type |
public void setDbRequestType(DbRequestType type) { |
||||||
*/ |
dbRequestType = type; |
||||||
public void setDbRequestType(DbRequestType type) { |
} |
||||||
dbRequestType = type; |
|
||||||
} |
} |
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
|
|||||||
@ -1,27 +1,31 @@ |
|||||||
/* |
/* |
||||||
* Created on 21.06.2003 |
* Created on 21.06.2003 |
||||||
* |
* |
||||||
* To change the template for this generated file go to |
* To change the template for this generated file go to |
||||||
* Window>Preferences>Java>Code Generation>Code and Comments |
* Window>Preferences>Java>Code Generation>Code and Comments |
||||||
*/ |
*/ |
||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
/** |
/** |
||||||
* @author MB |
* @author MB |
||||||
* |
* |
||||||
* To change the template for this generated type comment go to |
* To change the template for this generated type comment go to |
||||||
* Window>Preferences>Java>Code Generation>Code and Comments |
* Window>Preferences>Java>Code Generation>Code and Comments |
||||||
*/ |
*/ |
||||||
public class DbRequestType { |
public class DbRequestType { |
||||||
|
|
||||||
private final String name; |
private final String name; |
||||||
|
|
||||||
public static final DbRequestType QUERY=new DbRequestType("QUERY"); |
public static final DbRequestType QUERY = new DbRequestType("QUERY"); |
||||||
public static final DbRequestType UPDATE=new DbRequestType("UPDATE"); |
|
||||||
private DbRequestType(String name) |
public static final DbRequestType UPDATE = new DbRequestType("UPDATE"); |
||||||
{ |
|
||||||
this.name=name; |
private DbRequestType(String name) { |
||||||
} |
this.name = name; |
||||||
public String toString() {return name; |
} |
||||||
} |
|
||||||
} |
@Override |
||||||
|
public String toString() { |
||||||
|
return name; |
||||||
|
} |
||||||
|
} |
||||||
|
|||||||
@ -1,58 +1,69 @@ |
|||||||
/* |
/* |
||||||
* Created on 21.06.2003 |
* Created on 21.06.2003 |
||||||
* |
* |
||||||
* To change the template for this generated file go to |
* To change the template for this generated file go to |
||||||
* Window>Preferences>Java>Code Generation>Code and Comments |
* Window>Preferences>Java>Code Generation>Code and Comments |
||||||
*/ |
*/ |
||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import java.util.Collection; |
import java.util.Collection; |
||||||
|
|
||||||
/** |
/** |
||||||
* @author MB |
* @author MB |
||||||
* |
* |
||||||
* To change the template for this generated type comment go to |
* To change the template for this generated type comment go to |
||||||
* Window>Preferences>Java>Code Generation>Code and Comments |
* Window>Preferences>Java>Code Generation>Code and Comments |
||||||
*/ |
*/ |
||||||
public class DbResponse implements java.io.Serializable { |
public class DbResponse implements java.io.Serializable { |
||||||
static final long serialVersionUID = -3L; |
static final long serialVersionUID = -3L; |
||||||
private Collection result; |
|
||||||
private boolean OK; |
private Collection result; |
||||||
private Exception exception; |
|
||||||
private int updatedRowsCount; |
private boolean OK; |
||||||
|
|
||||||
/** |
private Exception exception; |
||||||
* MyServletResponse constructor comment. |
|
||||||
*/ |
private int updatedRowsCount; |
||||||
public DbResponse(Collection result, boolean OK, Exception exception) { |
|
||||||
this.result = result; |
/** |
||||||
this.OK = OK; |
* MyServletResponse constructor comment. |
||||||
this.exception = exception; |
*/ |
||||||
} |
public DbResponse(Collection result, boolean OK, Exception exception) { |
||||||
public Exception getException() { |
this.result = result; |
||||||
return exception; |
this.OK = OK; |
||||||
} |
this.exception = exception; |
||||||
public Collection getResult() { |
} |
||||||
return result; |
|
||||||
} |
public Exception getException() { |
||||||
public boolean isOK() { |
return exception; |
||||||
return OK; |
} |
||||||
} |
|
||||||
public void setException(Exception exception) { |
public Collection getResult() { |
||||||
this.exception = exception; |
return result; |
||||||
} |
} |
||||||
public void setOK(boolean OK) { |
|
||||||
this.OK = OK; |
public boolean isOK() { |
||||||
} |
return OK; |
||||||
public void setResult(Collection result) { |
} |
||||||
this.result = result; |
|
||||||
} |
public void setException(Exception exception) { |
||||||
public int getUpdatedRowsCount() { |
this.exception = exception; |
||||||
return updatedRowsCount; |
} |
||||||
} |
|
||||||
|
public void setOK(boolean OK) { |
||||||
public void setUpdatedRowsCount(int updatedRowsCount) { |
this.OK = OK; |
||||||
this.updatedRowsCount = updatedRowsCount; |
} |
||||||
} |
|
||||||
|
public void setResult(Collection result) { |
||||||
} |
this.result = result; |
||||||
|
} |
||||||
|
|
||||||
|
public int getUpdatedRowsCount() { |
||||||
|
return updatedRowsCount; |
||||||
|
} |
||||||
|
|
||||||
|
public void setUpdatedRowsCount(int updatedRowsCount) { |
||||||
|
this.updatedRowsCount = updatedRowsCount; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|||||||
@ -1,110 +1,105 @@ |
|||||||
/* |
/* |
||||||
* Created on 21.06.2003 |
* Created on 21.06.2003 |
||||||
* |
* |
||||||
* To change the template for this generated file go to |
* To change the template for this generated file go to |
||||||
* Window>Preferences>Java>Code Generation>Code and Comments |
* Window>Preferences>Java>Code Generation>Code and Comments |
||||||
*/ |
*/ |
||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import java.net.MalformedURLException; |
import java.net.MalformedURLException; |
||||||
import java.rmi.Naming; |
import java.rmi.Naming; |
||||||
import java.rmi.NotBoundException; |
import java.rmi.NotBoundException; |
||||||
import java.rmi.RMISecurityManager; |
import java.rmi.RMISecurityManager; |
||||||
import java.rmi.RemoteException; |
import java.rmi.RemoteException; |
||||||
import java.util.Iterator; |
import java.util.Iterator; |
||||||
import java.util.List; |
import java.util.List; |
||||||
|
|
||||||
/** |
/** |
||||||
* @author MB |
* @author MB |
||||||
* |
* |
||||||
* To change the template for this generated type comment go to |
* To change the template for this generated type comment go to |
||||||
* Window>Preferences>Java>Code Generation>Code and Comments |
* Window>Preferences>Java>Code Generation>Code and Comments |
||||||
*/ |
*/ |
||||||
public class DbRmiClient { |
public class DbRmiClient { |
||||||
private DbServerI dbServerI= null; |
private DbServerI dbServerI = null; |
||||||
String name="DbServer"; //"//localhost/DbServer"
|
|
||||||
public DbRmiClient() |
String name = "DbServer"; //"//localhost/DbServer"
|
||||||
{ |
|
||||||
if (System.getSecurityManager() == null) { |
public DbRmiClient() { |
||||||
System.setSecurityManager(new RMISecurityManager()); |
if (System.getSecurityManager() == null) { |
||||||
} |
System.setSecurityManager(new RMISecurityManager()); |
||||||
try { |
} |
||||||
dbServerI = (DbServerI)Naming.lookup(name); |
try { |
||||||
} catch (MalformedURLException e) { |
dbServerI = (DbServerI) Naming.lookup(name); |
||||||
e.printStackTrace(); |
} catch (MalformedURLException e) { |
||||||
} catch (RemoteException e) { |
e.printStackTrace(); |
||||||
e.printStackTrace(); |
} catch (RemoteException e) { |
||||||
} catch (NotBoundException e) { |
e.printStackTrace(); |
||||||
e.printStackTrace(); |
} catch (NotBoundException e) { |
||||||
} |
e.printStackTrace(); |
||||||
} |
} |
||||||
public void test() |
} |
||||||
{ |
|
||||||
testUpdate(); |
public void test() { |
||||||
testQuery(); |
testUpdate(); |
||||||
} |
testQuery(); |
||||||
private void testUpdate() { |
} |
||||||
try { |
|
||||||
|
private void testUpdate() { |
||||||
DbRequest dbRequest=new DbRequest("update dummy set col2=99"); |
try { |
||||||
DbResponse dbResponse=dbServerI.execute(dbRequest); |
|
||||||
if (dbResponse.isOK()) |
DbRequest dbRequest = new DbRequest("update dummy set col2=99"); |
||||||
{ |
DbResponse dbResponse = dbServerI.execute(dbRequest); |
||||||
System.out.println("OK - updated rows :" + dbResponse.getUpdatedRowsCount()); |
if (dbResponse.isOK()) { |
||||||
} |
System.out.println("OK - updated rows :" + dbResponse.getUpdatedRowsCount()); |
||||||
else |
} else { |
||||||
{ |
System.out.println("failed :" + dbResponse.getException()); |
||||||
System.out.println("failed :"+dbResponse.getException()); |
} |
||||||
} |
|
||||||
|
|
||||||
|
} catch (Exception e) { |
||||||
} catch (Exception e) { |
System.out.println(" exception: " + e.getMessage()); |
||||||
System.out.println(" exception: " + e.getMessage()); |
e.printStackTrace(); |
||||||
e.printStackTrace(); |
} |
||||||
} |
} |
||||||
} |
|
||||||
|
private void testQuery() { |
||||||
private void testQuery() { |
try { |
||||||
try { |
|
||||||
|
DbRequest dbRequest = new DbRequest("select * from dummy"); |
||||||
DbRequest dbRequest=new DbRequest("select * from dummy"); |
DbResponse dbResponse = dbServerI.executeQuery("select * from dummy"); |
||||||
DbResponse dbResponse=dbServerI.executeQuery("select * from dummy"); |
if (dbResponse.isOK()) { |
||||||
if (dbResponse.isOK()) |
System.out.println("OK"); |
||||||
{ |
List result = (List) dbResponse.getResult(); |
||||||
System.out.println("OK"); |
System.out.println("rows:" + result.size()); |
||||||
List result=(List)dbResponse.getResult(); |
int i = 0; |
||||||
System.out.println("rows:"+result.size()); |
for (Iterator it = result.iterator(); it.hasNext();) { |
||||||
int i=0; |
List row = (List) it.next(); |
||||||
for (Iterator it=result.iterator();it.hasNext();) |
i++; |
||||||
{ |
System.out.print("row " + i + " "); |
||||||
List row=(List)it.next(); |
for (Iterator it2 = row.iterator(); it2.hasNext();) { |
||||||
i++; |
Object o = it2.next(); |
||||||
System.out.print("row "+i+" "); |
System.out.print(" - " + o); |
||||||
for (Iterator it2=row.iterator();it2.hasNext();) |
} |
||||||
{ |
System.out.println(""); |
||||||
Object o=it2.next(); |
} |
||||||
System.out.print(" - "+o); |
|
||||||
} |
} else { |
||||||
System.out.println(""); |
System.out.println("failed :" + dbResponse.getException()); |
||||||
} |
} |
||||||
|
|
||||||
} |
|
||||||
else |
} catch (Exception e) { |
||||||
{ |
System.out.println(" exception: " + e.getMessage()); |
||||||
System.out.println("failed :"+dbResponse.getException()); |
e.printStackTrace(); |
||||||
} |
} |
||||||
|
} |
||||||
|
|
||||||
} catch (Exception e) { |
public static void main(String a[]) { |
||||||
System.out.println(" exception: " + e.getMessage()); |
DbRmiClient c = new DbRmiClient(); |
||||||
e.printStackTrace(); |
c.test(); |
||||||
} |
|
||||||
} |
|
||||||
public static void main(String a[]) { |
} |
||||||
DbRmiClient c=new DbRmiClient(); |
|
||||||
c.test(); |
} |
||||||
|
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|||||||
@ -1,23 +1,26 @@ |
|||||||
/* |
/* |
||||||
* Created on 21.06.2003 |
* Created on 21.06.2003 |
||||||
* |
* |
||||||
* To change the template for this generated file go to |
* To change the template for this generated file go to |
||||||
* Window>Preferences>Java>Code Generation>Code and Comments |
* Window>Preferences>Java>Code Generation>Code and Comments |
||||||
*/ |
*/ |
||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import java.rmi.Remote; |
import java.rmi.Remote; |
||||||
import java.rmi.RemoteException; |
import java.rmi.RemoteException; |
||||||
|
|
||||||
/** |
/** |
||||||
* @author MB |
* @author MB |
||||||
* |
* |
||||||
* To change the template for this generated type comment go to |
* To change the template for this generated type comment go to |
||||||
* Window>Preferences>Java>Code Generation>Code and Comments |
* Window>Preferences>Java>Code Generation>Code and Comments |
||||||
*/ |
*/ |
||||||
public interface DbServerI extends Remote { |
public interface DbServerI extends Remote { |
||||||
public DbResponse execute(String sql) throws RemoteException; |
public DbResponse execute(String sql) throws RemoteException; |
||||||
public DbResponse executeQuery(String sql) throws RemoteException; |
|
||||||
public DbResponse execute(DbRequest dbRequest) throws RemoteException; |
public DbResponse executeQuery(String sql) throws RemoteException; |
||||||
public DbResponse executeQuery(DbRequest dbRequest) throws RemoteException; |
|
||||||
} |
public DbResponse execute(DbRequest dbRequest) throws RemoteException; |
||||||
|
|
||||||
|
public DbResponse executeQuery(DbRequest dbRequest) throws RemoteException; |
||||||
|
} |
||||||
|
|||||||
@ -1,117 +1,126 @@ |
|||||||
/* |
/* |
||||||
* Created on 21.06.2003 |
* Created on 21.06.2003 |
||||||
* |
* |
||||||
* To change the template for this generated file go to |
* To change the template for this generated file go to |
||||||
* Window>Preferences>Java>Code Generation>Code and Comments |
* Window>Preferences>Java>Code Generation>Code and Comments |
||||||
*/ |
*/ |
||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import java.rmi.Naming; |
import java.rmi.Naming; |
||||||
import java.rmi.RMISecurityManager; |
import java.rmi.RMISecurityManager; |
||||||
import java.rmi.RemoteException; |
import java.rmi.RemoteException; |
||||||
import java.rmi.server.UnicastRemoteObject; |
import java.rmi.server.UnicastRemoteObject; |
||||||
import java.sql.Connection; |
import java.sql.Connection; |
||||||
import java.sql.ResultSet; |
import java.sql.ResultSet; |
||||||
import java.sql.SQLException; |
import java.sql.SQLException; |
||||||
import java.sql.Statement; |
import java.sql.Statement; |
||||||
import java.util.List; |
import java.util.List; |
||||||
|
|
||||||
/** |
/** |
||||||
* @author MB |
* @author MB |
||||||
* |
* |
||||||
* To change the template for this generated type comment go to |
* To change the template for this generated type comment go to |
||||||
* Window>Preferences>Java>Code Generation>Code and Comments |
* Window>Preferences>Java>Code Generation>Code and Comments |
||||||
*/ |
*/ |
||||||
public class DbServerImpl |
public class DbServerImpl extends UnicastRemoteObject implements de.memtext.db.DbServerI { |
||||||
extends UnicastRemoteObject |
private String dbDriver = "org.hsqldb.jdbcDriver"; |
||||||
implements de.memtext.db.DbServerI { |
|
||||||
private String dbDriver = "org.hsqldb.jdbcDriver"; |
private String dbURL = "jdbc:hsqldb:hsql://localhost:9000"; |
||||||
private String dbURL = "jdbc:hsqldb:hsql://localhost:9000"; |
|
||||||
private String userid = "SA"; |
private String userid = "SA"; |
||||||
private String passwd = ""; |
|
||||||
private int updateRowCount; |
private String passwd = ""; |
||||||
private Connection con; |
|
||||||
private Statement stmt; |
private int updateRowCount; |
||||||
public DbServerImpl() throws RemoteException { |
|
||||||
super(); |
private Connection con; |
||||||
ConnectionCreator.loadClass(dbDriver); |
|
||||||
try { |
private Statement stmt; |
||||||
con = ConnectionCreator.getConnection(dbURL, userid, passwd); |
|
||||||
stmt = con.createStatement(); |
public DbServerImpl() throws RemoteException { |
||||||
} catch (Exception e) { |
super(); |
||||||
e.printStackTrace(); |
ConnectionCreator.loadClass(dbDriver); |
||||||
throw new RemoteException("Couldn't connect to DB" + e.toString()); |
try { |
||||||
} |
con = ConnectionCreator.getConnection(dbURL, userid, passwd); |
||||||
} |
stmt = con.createStatement(); |
||||||
public DbResponse execute(String sql) throws RemoteException { |
} catch (Exception e) { |
||||||
DbResponse result = new DbResponse(null, true, null); |
e.printStackTrace(); |
||||||
try { |
throw new RemoteException("Couldn't connect to DB" + e.toString()); |
||||||
updateRowCount = stmt.executeUpdate(sql); |
} |
||||||
result.setUpdatedRowsCount(updateRowCount); |
} |
||||||
result.setOK(true); |
|
||||||
} catch (SQLException e) { |
@Override |
||||||
e.printStackTrace(); |
public DbResponse execute(String sql) throws RemoteException { |
||||||
result.setOK(false); |
DbResponse result = new DbResponse(null, true, null); |
||||||
result.setException(e); |
try { |
||||||
} |
updateRowCount = stmt.executeUpdate(sql); |
||||||
return result; |
result.setUpdatedRowsCount(updateRowCount); |
||||||
} |
result.setOK(true); |
||||||
|
} catch (SQLException e) { |
||||||
/* (non-Javadoc) |
e.printStackTrace(); |
||||||
* @see de.mbisping.db.DbServerI#execute(de.mbisping.db.DbRequest) |
result.setOK(false); |
||||||
*/ |
result.setException(e); |
||||||
public DbResponse execute(DbRequest dbRequest) throws RemoteException { |
} |
||||||
DbResponse result = new DbResponse(null, true, null); |
return result; |
||||||
if (dbRequest.getSql() != null) |
} |
||||||
result = execute(dbRequest.getSql()); |
|
||||||
|
/* (non-Javadoc) |
||||||
return result; |
* @see de.mbisping.db.DbServerI#execute(de.mbisping.db.DbRequest) |
||||||
} |
*/ |
||||||
|
@Override |
||||||
public DbResponse executeQuery(String sql) throws RemoteException { |
public DbResponse execute(DbRequest dbRequest) throws RemoteException { |
||||||
DbResponse result = new DbResponse(null, true, null); |
DbResponse result = new DbResponse(null, true, null); |
||||||
try { |
if (dbRequest.getSql() != null) result = execute(dbRequest.getSql()); |
||||||
ResultSet rs=stmt.executeQuery(sql); |
|
||||||
List list=DbUtils.toResultList(rs); |
return result; |
||||||
result.setResult(list); |
} |
||||||
result.setOK(true); |
|
||||||
} catch (SQLException e) { |
@Override |
||||||
e.printStackTrace(); |
public DbResponse executeQuery(String sql) throws RemoteException { |
||||||
result.setOK(false); |
DbResponse result = new DbResponse(null, true, null); |
||||||
result.setException(e); |
try { |
||||||
} |
ResultSet rs = stmt.executeQuery(sql); |
||||||
return result; |
List list = DbUtils.toResultList(rs); |
||||||
} |
result.setResult(list); |
||||||
/* (non-Javadoc) |
result.setOK(true); |
||||||
* @see de.mbisping.db.DbServerI#executeQuery(de.mbisping.db.DbRequest) |
} catch (SQLException e) { |
||||||
*/ |
e.printStackTrace(); |
||||||
public DbResponse executeQuery(DbRequest dbRequest) |
result.setOK(false); |
||||||
throws RemoteException { |
result.setException(e); |
||||||
DbResponse result = new DbResponse(null, true, null); |
} |
||||||
result.setUpdatedRowsCount(20); |
return result; |
||||||
return result; |
} |
||||||
} |
|
||||||
|
/* (non-Javadoc) |
||||||
public static void main(String args[]) { |
* @see de.mbisping.db.DbServerI#executeQuery(de.mbisping.db.DbRequest) |
||||||
|
*/ |
||||||
// Create and install a security manager
|
@Override |
||||||
if (System.getSecurityManager() == null) { |
public DbResponse executeQuery(DbRequest dbRequest) throws RemoteException { |
||||||
System.setSecurityManager(new RMISecurityManager()); |
DbResponse result = new DbResponse(null, true, null); |
||||||
} |
result.setUpdatedRowsCount(20); |
||||||
|
return result; |
||||||
try { |
} |
||||||
|
|
||||||
DbServerImpl obj = new DbServerImpl(); |
public static void main(String args[]) { |
||||||
//String name="//localhost/DbServer";
|
|
||||||
String name = "DbServer"; |
// Create and install a security manager
|
||||||
// Bind this object instance to the name "HelloServer"
|
if (System.getSecurityManager() == null) { |
||||||
Naming.rebind(name, obj); |
System.setSecurityManager(new RMISecurityManager()); |
||||||
|
} |
||||||
System.out.println(name + " bound in registry"); |
|
||||||
} catch (Exception e) { |
try { |
||||||
System.out.println("DbServerImpl err: " + e.getMessage()); |
|
||||||
e.printStackTrace(); |
DbServerImpl obj = new DbServerImpl(); |
||||||
} |
//String name="//localhost/DbServer";
|
||||||
} |
String name = "DbServer"; |
||||||
|
// Bind this object instance to the name "HelloServer"
|
||||||
} |
Naming.rebind(name, obj); |
||||||
|
|
||||||
|
System.out.println(name + " bound in registry"); |
||||||
|
} catch (Exception e) { |
||||||
|
System.out.println("DbServerImpl err: " + e.getMessage()); |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|||||||
@ -1,177 +1,99 @@ |
|||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import java.sql.Connection; |
import java.sql.DriverManager; |
||||||
import java.sql.DriverManager; |
import java.sql.ResultSet; |
||||||
import java.sql.PreparedStatement; |
import java.sql.ResultSetMetaData; |
||||||
import java.sql.ResultSet; |
import java.sql.SQLException; |
||||||
import java.sql.ResultSetMetaData; |
import java.util.Iterator; |
||||||
import java.sql.SQLException; |
import java.util.LinkedList; |
||||||
import java.sql.Statement; |
import java.util.List; |
||||||
import java.util.Iterator; |
|
||||||
import java.util.LinkedList; |
/** |
||||||
import java.util.List; |
* @author MB |
||||||
|
*/ |
||||||
/** |
public class DbUtils { |
||||||
* @author MB |
|
||||||
*/ |
/** |
||||||
public class DbUtils { |
* |
||||||
|
*/ |
||||||
/** |
private DbUtils() { |
||||||
* |
} |
||||||
*/ |
|
||||||
private DbUtils() { |
/* private Vector toResultVector(ResultSet rs) throws SQLException |
||||||
} |
{ |
||||||
|
Vector help = new Vector(); |
||||||
/* |
ResultSetMetaData rsmd = rs.getMetaData(); |
||||||
* private Vector toResultVector(ResultSet rs) throws SQLException { Vector help |
int numberOfColumns = rsmd.getColumnCount(); |
||||||
* = new Vector(); ResultSetMetaData rsmd = rs.getMetaData(); int |
|
||||||
* numberOfColumns = rsmd.getColumnCount(); |
Vector row = null; |
||||||
* |
while (rs.next()) { |
||||||
* Vector row = null; while (rs.next()) { row = new Vector(); for (int i = 1; i |
row = new Vector(); |
||||||
* <= numberOfColumns; i++) { row.add(rs.getObject(i)); } help.add(row); } |
for (int i = 1; i <= numberOfColumns; i++) { |
||||||
* rs.close(); return help; |
row.add(rs.getObject(i)); |
||||||
* |
} |
||||||
* } |
help.add(row); |
||||||
*/ |
} |
||||||
public static List toResultList(ResultSet rs) throws SQLException { |
rs.close(); |
||||||
List help = new LinkedList(); |
return help; |
||||||
ResultSetMetaData rsmd = rs.getMetaData(); |
|
||||||
int numberOfColumns = rsmd.getColumnCount(); |
}*/ |
||||||
|
public static List toResultList(ResultSet rs) throws SQLException { |
||||||
List row = null; |
List help = new LinkedList(); |
||||||
while (rs.next()) { |
ResultSetMetaData rsmd = rs.getMetaData(); |
||||||
row = new LinkedList(); |
int numberOfColumns = rsmd.getColumnCount(); |
||||||
for (int i = 1; i <= numberOfColumns; i++) { |
|
||||||
row.add(rs.getObject(i)); |
List row = null; |
||||||
} |
while (rs.next()) { |
||||||
help.add(row); |
row = new LinkedList(); |
||||||
} |
for (int i = 1; i <= numberOfColumns; i++) { |
||||||
rs.close(); |
row.add(rs.getObject(i)); |
||||||
return help; |
} |
||||||
} |
help.add(row); |
||||||
|
} |
||||||
public static void grantRightToAllTables() { |
rs.close(); |
||||||
String url = "jdbc:hsqldb:hsql://localhost:9999"; |
return help; |
||||||
String user = ""; |
} |
||||||
String right = "select"; |
|
||||||
try { |
public static void grantRightToAllTables() throws SQLException { |
||||||
Class.forName("org.hsqldb.jdbcDriver"); |
String url = "jdbc:hsqldb:hsql://localhost:9999"; |
||||||
} catch (ClassNotFoundException e) { |
String user = ""; |
||||||
e.printStackTrace(); |
String right = "select"; |
||||||
} |
try { |
||||||
|
Class.forName("org.hsqldb.jdbcDriver"); |
||||||
try { |
} catch (ClassNotFoundException e) { |
||||||
DBAccess.addConnection("dbConn", DriverManager.getConnection(url, "admin", "hatschi3000")); |
e.printStackTrace(); |
||||||
} catch (SQLException e1) { |
} |
||||||
e1.printStackTrace(); |
|
||||||
} catch (Exception e1) { |
try { |
||||||
e1.printStackTrace(); |
DBAccess.addConnection("dbConn", DriverManager.getConnection(url, "admin", "hatschi3000")); |
||||||
} |
} catch (SQLException e1) { |
||||||
List tablist = DBAccess.get("dbConn").getTableList(); |
e1.printStackTrace(); |
||||||
StringBuffer buf = new StringBuffer(); |
} catch (Exception e1) { |
||||||
for (Iterator it = tablist.iterator(); it.hasNext();) { |
e1.printStackTrace(); |
||||||
String tabname = (String) it.next(); |
} |
||||||
buf.append("grant " + right + " on " + tabname + " to " + user + ";"); |
List tablist = DBAccess.get("dbConn").getTableList(); |
||||||
|
StringBuffer buf = new StringBuffer(); |
||||||
} |
for (Iterator it = tablist.iterator(); it.hasNext();) { |
||||||
DBAccess.get("dbConn").execute(buf.toString()); |
String tabname = (String) it.next(); |
||||||
|
buf.append("grant " + right + " on " + tabname + " to " + user + ";"); |
||||||
DBAccess.closeConnection("dbConn"); |
|
||||||
|
} |
||||||
} |
DBAccess.get("dbConn").execute(buf.toString()); |
||||||
|
|
||||||
/** |
|
||||||
* Places Object in inverted single commas if it isn't null |
|
||||||
* |
DBAccess.closeConnection("dbConn"); |
||||||
* @param val |
|
||||||
* @return either "null" if val is null or "'val'" |
} |
||||||
*/ |
|
||||||
public static String placeInInvertedCommas(Object val) { |
/** |
||||||
if (val == null) |
* Places Object in inverted single commas if it isn't null |
||||||
return "null"; |
* @param val |
||||||
return "'" + val + "'"; |
* @return either "null" if val is null or "'val'" |
||||||
} |
*/ |
||||||
|
public static String placeInInvertedCommas(Object val) { |
||||||
|
if (val == null) return "null"; |
||||||
public static int getInt(Statement stm, String query) throws SQLException { |
return "'" + val + "'"; |
||||||
int result = -1; |
} |
||||||
ResultSet rs = stm.executeQuery(query); |
} |
||||||
while (rs.next()) { |
|
||||||
result = rs.getInt(1); |
|
||||||
} |
|
||||||
rs.close(); |
|
||||||
|
|
||||||
return result; |
|
||||||
} |
|
||||||
|
|
||||||
public static String getString(Statement stm, String query) throws SQLException { |
|
||||||
String result = null; |
|
||||||
ResultSet rs = stm.executeQuery(query); |
|
||||||
while (rs.next()) { |
|
||||||
result = rs.getString(1); |
|
||||||
} |
|
||||||
rs.close(); |
|
||||||
|
|
||||||
return result; |
|
||||||
} |
|
||||||
/** |
|
||||||
* |
|
||||||
* @param query |
|
||||||
* @return -1 wenn nichts gefunden |
|
||||||
* @throws SQLException |
|
||||||
*/ |
|
||||||
public static int getInt(Connection con, String query,int param) throws SQLException { |
|
||||||
int result = -1; |
|
||||||
PreparedStatement pst=con.prepareStatement(query); |
|
||||||
pst.setInt(1, param); |
|
||||||
ResultSet rs = pst.executeQuery(); |
|
||||||
while (rs.next()) { |
|
||||||
result = rs.getInt(1); |
|
||||||
} |
|
||||||
rs.close(); |
|
||||||
pst.close(); |
|
||||||
return result; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* |
|
||||||
* @param query |
|
||||||
* @return -1 wenn nichts gefunden |
|
||||||
* @throws SQLException |
|
||||||
*/ |
|
||||||
public static int getInt(Connection con, String query,String param) throws SQLException { |
|
||||||
int result = -1; |
|
||||||
PreparedStatement pst=con.prepareStatement(query); |
|
||||||
pst.setString(1, param); |
|
||||||
ResultSet rs = pst.executeQuery(); |
|
||||||
while (rs.next()) { |
|
||||||
result = rs.getInt(1); |
|
||||||
} |
|
||||||
rs.close(); |
|
||||||
pst.close(); |
|
||||||
return result; |
|
||||||
} |
|
||||||
/** |
|
||||||
* |
|
||||||
* @param con |
|
||||||
* @param query |
|
||||||
* @param param |
|
||||||
* @return null if nothing found |
|
||||||
* @throws SQLException |
|
||||||
*/ |
|
||||||
public static String getString(Connection con,String query,String param) throws SQLException |
|
||||||
{ |
|
||||||
String result=null; |
|
||||||
PreparedStatement pst=con.prepareStatement(query); |
|
||||||
pst.setString(1, param); |
|
||||||
ResultSet rs = pst.executeQuery(); |
|
||||||
while (rs.next()) { |
|
||||||
result = rs.getString(1); |
|
||||||
} |
|
||||||
rs.close(); |
|
||||||
pst.close(); |
|
||||||
return result; |
|
||||||
|
|
||||||
} |
|
||||||
} |
|
||||||
//Created on 21.06.2003
|
//Created on 21.06.2003
|
||||||
@ -1,123 +1,69 @@ |
|||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import java.sql.Statement; |
import java.sql.Statement; |
||||||
|
|
||||||
/** |
/** |
||||||
* @author MB |
* @author MB |
||||||
* |
* |
||||||
* To change this generated comment edit the template variable "typecomment": |
* To change this generated comment edit the template variable "typecomment": |
||||||
* Window>Preferences>Java>Templates. |
* Window>Preferences>Java>Templates. |
||||||
* To enable and disable the creation of type comments go to |
* To enable and disable the creation of type comments go to |
||||||
* Window>Preferences>Java>Code Generation. |
* Window>Preferences>Java>Code Generation. |
||||||
*/ |
*/ |
||||||
public class HsqlProcedures { |
public class HsqlProcedures { |
||||||
|
|
||||||
/** |
/** |
||||||
* Constructor for HsqlProcedures. |
* Constructor for HsqlProcedures. |
||||||
*/ |
*/ |
||||||
private HsqlProcedures() { |
private HsqlProcedures() { |
||||||
super(); |
super(); |
||||||
} |
} |
||||||
|
|
||||||
public static Integer get1() |
public static Integer get1() { |
||||||
{ |
return Integer.valueOf(1); |
||||||
return new Integer(1); |
|
||||||
|
} |
||||||
} |
|
||||||
public static void alterTableColumnIntegerToVarchar( |
public static void alterTableColumnIntegerToVarchar(java.sql.Connection con, String tablename, String columnname) { |
||||||
java.sql.Connection con, |
try { |
||||||
String tablename, |
Statement stmt = con.createStatement(); |
||||||
String columnname) { |
// add new tmp varchar col
|
||||||
try { |
stmt.execute("alter table " + tablename + " add column tmp" + columnname + " varchar"); |
||||||
Statement stmt = con.createStatement(); |
//update value of tmp
|
||||||
// add new tmp varchar col
|
stmt.execute("update " + tablename + " set tmp" + columnname + "= " + columnname); |
||||||
stmt.execute( |
//drop original
|
||||||
"alter table " |
stmt.execute("alter table " + tablename + " drop column " + columnname); |
||||||
+ tablename |
//add col with original name and of varchar type
|
||||||
+ " add column tmp" |
stmt.execute("alter table " + tablename + " add column " + columnname + " varchar"); |
||||||
+ columnname |
//update values
|
||||||
+ " varchar"); |
stmt.execute("update " + tablename + " set " + columnname + "= tmp" + columnname); |
||||||
//update value of tmp
|
//drop tmp
|
||||||
stmt.execute( |
stmt.execute("alter table " + tablename + " drop column tmp" + columnname); |
||||||
"update " |
} catch (Exception e) { |
||||||
+ tablename |
e.printStackTrace(); |
||||||
+ " set tmp" |
} |
||||||
+ columnname |
|
||||||
+ "= " |
} |
||||||
+ columnname); |
|
||||||
//drop original
|
public static void alterTableColumnVarcharToInteger(java.sql.Connection con, String tablename, String columnname) { |
||||||
stmt.execute( |
try { |
||||||
"alter table " + tablename + " drop column " + columnname); |
Statement stmt = con.createStatement(); |
||||||
//add col with original name and of varchar type
|
// add new tmp varchar col
|
||||||
stmt.execute( |
stmt.execute("alter table " + tablename + " add column tmp" + columnname + " integer"); |
||||||
"alter table " |
//update value of tmp
|
||||||
+ tablename |
stmt.execute("update " + tablename + " set tmp" + columnname + "= " + columnname); |
||||||
+ " add column " |
//drop original
|
||||||
+ columnname |
stmt.execute("alter table " + tablename + " drop column " + columnname); |
||||||
+ " varchar"); |
//add col with original name and of varchar type
|
||||||
//update values
|
stmt.execute("alter table " + tablename + " add column " + columnname + " integer"); |
||||||
stmt.execute( |
//update values
|
||||||
"update " |
stmt.execute("update " + tablename + " set " + columnname + "= tmp" + columnname); |
||||||
+ tablename |
//drop tmp
|
||||||
+ " set " |
stmt.execute("alter table " + tablename + " drop column tmp" + columnname); |
||||||
+ columnname |
} catch (Exception e) { |
||||||
+ "= tmp" |
e.printStackTrace(); |
||||||
+ columnname); |
} |
||||||
//drop tmp
|
|
||||||
stmt.execute( |
} |
||||||
"alter table " + tablename + " drop column tmp" + columnname); |
|
||||||
} catch (Exception e) { |
} |
||||||
e.printStackTrace(); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
public static void alterTableColumnVarcharToInteger( |
|
||||||
java.sql.Connection con, |
|
||||||
String tablename, |
|
||||||
String columnname) { |
|
||||||
try { |
|
||||||
Statement stmt = con.createStatement(); |
|
||||||
// add new tmp varchar col
|
|
||||||
stmt.execute( |
|
||||||
"alter table " |
|
||||||
+ tablename |
|
||||||
+ " add column tmp" |
|
||||||
+ columnname |
|
||||||
+ " integer"); |
|
||||||
//update value of tmp
|
|
||||||
stmt.execute( |
|
||||||
"update " |
|
||||||
+ tablename |
|
||||||
+ " set tmp" |
|
||||||
+ columnname |
|
||||||
+ "= " |
|
||||||
+ columnname); |
|
||||||
//drop original
|
|
||||||
stmt.execute( |
|
||||||
"alter table " + tablename + " drop column " + columnname); |
|
||||||
//add col with original name and of varchar type
|
|
||||||
stmt.execute( |
|
||||||
"alter table " |
|
||||||
+ tablename |
|
||||||
+ " add column " |
|
||||||
+ columnname |
|
||||||
+ " integer"); |
|
||||||
//update values
|
|
||||||
stmt.execute( |
|
||||||
"update " |
|
||||||
+ tablename |
|
||||||
+ " set " |
|
||||||
+ columnname |
|
||||||
+ "= tmp" |
|
||||||
+ columnname); |
|
||||||
//drop tmp
|
|
||||||
stmt.execute( |
|
||||||
"alter table " + tablename + " drop column tmp" + columnname); |
|
||||||
} catch (Exception e) { |
|
||||||
e.printStackTrace(); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|||||||
@ -1,422 +1,381 @@ |
|||||||
/* |
/* |
||||||
* Copyright (c) 2001-2004, The HSQL Development Group All rights reserved. |
* Copyright (c) 2001-2004, The HSQL Development Group All rights reserved. |
||||||
* |
* |
||||||
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
||||||
* modification, are permitted provided that the following conditions are met: |
* modification, are permitted provided that the following conditions are met: |
||||||
* |
* |
||||||
* Redistributions of source code must retain the above copyright notice, this |
* Redistributions of source code must retain the above copyright notice, this |
||||||
* list of conditions and the following disclaimer. |
* list of conditions and the following disclaimer. |
||||||
* |
* |
||||||
* Redistributions in binary form must reproduce the above copyright notice, |
* Redistributions in binary form must reproduce the above copyright notice, |
||||||
* this list of conditions and the following disclaimer in the documentation |
* this list of conditions and the following disclaimer in the documentation |
||||||
* and/or other materials provided with the distribution. |
* and/or other materials provided with the distribution. |
||||||
* |
* |
||||||
* Neither the name of the HSQL Development Group nor the names of its |
* Neither the name of the HSQL Development Group nor the names of its |
||||||
* contributors may be used to endorse or promote products derived from this |
* contributors may be used to endorse or promote products derived from this |
||||||
* software without specific prior written permission. |
* software without specific prior written permission. |
||||||
* |
* |
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG, OR |
* ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG, OR |
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
||||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
||||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
||||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
||||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||||
*/ |
*/ |
||||||
|
|
||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import java.awt.Component; |
import java.awt.Component; |
||||||
import java.io.BufferedInputStream; |
import java.io.BufferedInputStream; |
||||||
import java.io.BufferedOutputStream; |
import java.io.BufferedOutputStream; |
||||||
import java.io.File; |
import java.io.File; |
||||||
import java.io.FileInputStream; |
import java.io.FileInputStream; |
||||||
import java.io.FileOutputStream; |
import java.io.FileOutputStream; |
||||||
import java.io.FilenameFilter; |
import java.io.FilenameFilter; |
||||||
import java.io.IOException; |
import java.io.IOException; |
||||||
import java.sql.Connection; |
import java.sql.Connection; |
||||||
import java.sql.ResultSet; |
import java.sql.ResultSet; |
||||||
import java.sql.SQLException; |
import java.sql.SQLException; |
||||||
import java.sql.Statement; |
import java.sql.Statement; |
||||||
import java.util.Properties; |
import java.util.Properties; |
||||||
import java.util.ResourceBundle; |
import java.util.ResourceBundle; |
||||||
|
|
||||||
import javax.swing.JOptionPane; |
import javax.swing.JOptionPane; |
||||||
|
|
||||||
/** |
/** |
||||||
* A class which helps managing multiple connections to a stand-alone database |
* A class which helps managing multiple connections to a stand-alone database |
||||||
* (e.g. on a network path). After one user has opened the database other users |
* (e.g. on a network path). After one user has opened the database other users |
||||||
* can get the option to open a temporary copy of the database. The temporary |
* can get the option to open a temporary copy of the database. The temporary |
||||||
* copy may be read-only, but doesn't has to be. If it's not read-only all, all |
* copy may be read-only, but doesn't has to be. If it's not read-only all, all |
||||||
* changes will be discarded when the connection is closed. (May be useful if |
* changes will be discarded when the connection is closed. (May be useful if |
||||||
* the application only does some dispensible logging or so). see |
* the application only does some dispensible logging or so). see |
||||||
* SampleApplication |
* SampleApplication |
||||||
*/ |
*/ |
||||||
public class HsqlStandaloneMgr { |
public class HsqlStandaloneMgr { |
||||||
private static AbstractHsqlStandaloneMgrResources resources; |
private static AbstractHsqlStandaloneMgrResources resources; |
||||||
|
|
||||||
private HsqlStandaloneMgr() { |
private HsqlStandaloneMgr() { |
||||||
} |
} |
||||||
|
|
||||||
private static void initResources() { |
private static void initResources() { |
||||||
String mypackage = ""; |
String mypackage = ""; |
||||||
//if you place the Resources classes in some package, define it like this
|
//if you place the Resources classes in some package, define it like this
|
||||||
mypackage="de.memtext.db."; |
mypackage = "de.memtext.db."; |
||||||
resources = (AbstractHsqlStandaloneMgrResources) ResourceBundle |
resources = (AbstractHsqlStandaloneMgrResources) ResourceBundle.getBundle(mypackage + "HsqlStandaloneMgrResources"); |
||||||
.getBundle(mypackage + "HsqlStandaloneMgrResources"); |
} |
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
/** |
* Checks if a database is already opened (by checking if a .lck file |
||||||
* Checks if a database is already opened (by checking if a .lck file |
* exists) Use from HSQLDB 1.7.2 or higher |
||||||
* exists) Use from HSQLDB 1.7.2 or higher |
* |
||||||
* |
* @param String |
||||||
* @param String |
* path - null,"" or "." for current directory |
||||||
* path - null,"" or "." for current directory |
* @param String |
||||||
* @param String |
* databasename |
||||||
* databasename |
* @return true if database is already opened |
||||||
* @return true if database is already opened |
*/ |
||||||
*/ |
public static boolean isDatabaseOpen(String path, String databasename) { |
||||||
public static boolean isDatabaseOpen(String path, String databasename) { |
File lckFile = new File(getAdaptedPath(path) + databasename + ".lck"); |
||||||
File lckFile = new File(getAdaptedPath(path)+databasename+".lck"); |
return lckFile.exists(); |
||||||
return lckFile.exists(); |
} |
||||||
} |
|
||||||
|
/** |
||||||
/** |
* Deletes any temporary files which the HsqlStandaloneMgr may have created |
||||||
* Deletes any temporary files which the HsqlStandaloneMgr may have created |
* for the given url |
||||||
* for the given url |
* |
||||||
* |
* @param String |
||||||
* @param String |
* url |
||||||
* url |
* @param String |
||||||
* @param String |
* path - null,"" or "." for current dir |
||||||
* path - null,"" or "." for current dir |
* @param String |
||||||
* @param String |
* databasename - of the original database, no _TMP_COPY appendix |
||||||
* databasename - of the original database, no _TMP_COPY appendix |
*/ |
||||||
*/ |
public static void deleteTmpFiles(String url, String path, String databasename) { |
||||||
public static void deleteTmpFiles(String url, String path, |
if (databasename.indexOf("_TMP_COPY") > -1) throw new IllegalArgumentException("Please specifiy the name of the original database without _TMP_COPY"); |
||||||
String databasename) { |
path = getAdaptedPath(path); |
||||||
if (databasename.indexOf("_TMP_COPY") > -1) |
|
||||||
throw new IllegalArgumentException( |
int tmpPos = url.indexOf("_TMP_COPY"); |
||||||
"Please specifiy the name of the original database without _TMP_COPY"); |
if (tmpPos == -1) { |
||||||
path=getAdaptedPath(path); |
//if the main connection is closed delete info about the user
|
||||||
|
File f = new File(path + databasename + "_user.properties"); |
||||||
int tmpPos = url.indexOf("_TMP_COPY"); |
if (f.exists()) f.delete(); |
||||||
if (tmpPos == -1) { |
} else { |
||||||
//if the main connection is closed delete info about the user
|
//delete files for temp. connection
|
||||||
File f = new File(path + databasename + "_user.properties"); |
String tmp = url.substring(tmpPos); |
||||||
if (f.exists()) |
if (path == null || path.equals("")) path = "."; |
||||||
f.delete(); |
File fpath = new File(path); |
||||||
} else { |
File tmpFiles[] = fpath.listFiles(new TmpFileFilter(databasename + tmp)); |
||||||
//delete files for temp. connection
|
for (int i = 0; i < tmpFiles.length; i++) { |
||||||
String tmp = url.substring(tmpPos); |
tmpFiles[i].delete(); |
||||||
if (path==null||path.equals("")) path="."; |
} |
||||||
File fpath = new File(path); |
} |
||||||
File tmpFiles[] = fpath.listFiles(new TmpFileFilter(databasename |
|
||||||
+ tmp)); |
} |
||||||
for (int i = 0; i < tmpFiles.length; i++) { |
|
||||||
tmpFiles[i].delete(); |
/** |
||||||
} |
* Asks the user if he/she wants to open a temporary copy of the database or |
||||||
} |
* not. A boolean indicates if the questions concerns read-only mode or not. |
||||||
|
* |
||||||
} |
* @param Component |
||||||
|
* parentComponent - usually the application Frame, but may be |
||||||
/** |
* null |
||||||
* Asks the user if he/she wants to open a temporary copy of the database or |
* @param String |
||||||
* not. A boolean indicates if the questions concerns read-only mode or not. |
* databasename - name of original database |
||||||
* |
* @param boolean |
||||||
* @param Component |
* isReadOnlyCopyWanted - should the temp. copy be read-only |
||||||
* parentComponent - usually the application Frame, but may be |
* @return int from JOptionPane.showConfirmDialog |
||||||
* null |
*/ |
||||||
* @param String |
public static int askUser(Component parentComponent, String path, |
||||||
* databasename - name of original database |
|
||||||
* @param boolean |
String databasename, boolean isReadOnlyCopyWanted) { |
||||||
* isReadOnlyCopyWanted - should the temp. copy be read-only |
if (resources == null) initResources(); |
||||||
* @return int from JOptionPane.showConfirmDialog |
|
||||||
*/ |
String username = null; |
||||||
public static int askUser(Component parentComponent, String path, |
File f = new File(getAdaptedPath(path) + databasename + "_user.properties"); |
||||||
|
if (f.exists()) { |
||||||
String databasename, boolean isReadOnlyCopyWanted) { |
Properties p = new Properties(); |
||||||
if (resources == null) |
FileInputStream fis; |
||||||
initResources(); |
try { |
||||||
|
fis = new FileInputStream(f); |
||||||
String username = null; |
p.load(fis); |
||||||
File f = new File(getAdaptedPath(path) + databasename + "_user.properties"); |
username = p.getProperty("user"); |
||||||
if (f.exists()) { |
fis.close(); |
||||||
Properties p = new Properties(); |
} catch (Exception e) { |
||||||
FileInputStream fis; |
System.err.println(resources.getString("Couldn't read user name")); |
||||||
try { |
e.printStackTrace(); |
||||||
fis = new FileInputStream(f); |
} |
||||||
p.load(fis); |
|
||||||
username = p.getProperty("user"); |
} |
||||||
fis.close(); |
StringBuffer msg = new StringBuffer(resources.getDbInUseBy(databasename, username)); |
||||||
} catch (Exception e) { |
|
||||||
System.err.println(resources |
if (isReadOnlyCopyWanted) |
||||||
.getString("Couldn't read user name")); |
msg.append(resources.getString("Would you like to open a temporary copy in read-only mode?")); |
||||||
e.printStackTrace(); |
else |
||||||
} |
msg.append(resources.getString("Would you like to open a temporary copy?\nAttention - any changes to the database will be lost after closing the program!")); |
||||||
|
return JOptionPane.showConfirmDialog(parentComponent, msg, "HSQLDB", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); |
||||||
} |
|
||||||
StringBuffer msg = new StringBuffer(resources.getDbInUseBy( |
} |
||||||
databasename, username)); |
|
||||||
|
/** |
||||||
if (isReadOnlyCopyWanted) |
* Returns a connection to a temporary copy of a database either in |
||||||
msg |
* read-only mode or not. |
||||||
.append(resources |
* |
||||||
.getString("Would you like to open a temporary copy in read-only mode?")); |
* @param Component |
||||||
else |
* parentComponent - usually the application Frame, but may be |
||||||
msg |
* null |
||||||
.append(resources |
* @param String |
||||||
.getString("Would you like to open a temporary copy?\nAttention - any changes to the database will be lost after closing the program!")); |
* path - null,"" or "." for current dir |
||||||
return JOptionPane.showConfirmDialog(parentComponent, msg, "HSQLDB", |
* @param String |
||||||
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); |
* databasename |
||||||
|
* @param String |
||||||
} |
* username |
||||||
|
* @param String |
||||||
/** |
* password |
||||||
* Returns a connection to a temporary copy of a database either in |
* @param boolean |
||||||
* read-only mode or not. |
* isReadOnlyCopyWanted - should the temporary copy of the |
||||||
* |
* database be in read-only mode |
||||||
* @param Component |
* @return Connection to the temporary copy of the database |
||||||
* parentComponent - usually the application Frame, but may be |
* @throws ClassNotFoundException |
||||||
* null |
* @throws SQLException |
||||||
* @param String |
* @throws IOException |
||||||
* path - null,"" or "." for current dir |
*/ |
||||||
* @param String |
public static Connection getTmpConnection(Component parentComponent, String path, String databasename, String username, String password, boolean isReadOnlyCopyWanted) |
||||||
* databasename |
throws ClassNotFoundException, SQLException, IOException { |
||||||
* @param String |
if (resources == null) initResources(); |
||||||
* username |
Class.forName("org.hsqldb.jdbcDriver"); |
||||||
* @param String |
path = getAdaptedPath(path); |
||||||
* password |
|
||||||
* @param boolean |
int tmpInstanceNumber = checkNumber(path, databasename); |
||||||
* isReadOnlyCopyWanted - should the temporary copy of the |
|
||||||
* database be in read-only mode |
try { |
||||||
* @return Connection to the temporary copy of the database |
copyDatabaseFiles(path, databasename, tmpInstanceNumber); |
||||||
* @throws ClassNotFoundException |
} catch (IOException e) { |
||||||
* @throws SQLException |
JOptionPane.showMessageDialog(parentComponent, resources.getString("Could not create temporary copy of database.)") + "\n" + e, "HSQLDB", JOptionPane.WARNING_MESSAGE); |
||||||
* @throws IOException |
throw e; |
||||||
*/ |
} |
||||||
public static Connection getTmpConnection(Component parentComponent, |
|
||||||
String path, String databasename, String username, String password, |
if (isReadOnlyCopyWanted) { |
||||||
boolean isReadOnlyCopyWanted) throws ClassNotFoundException, |
try { |
||||||
SQLException, IOException { |
setReadonly(path + databasename + "_TMP_COPY" + tmpInstanceNumber + ".properties"); |
||||||
if (resources == null) |
} catch (IOException e) { |
||||||
initResources(); |
JOptionPane.showMessageDialog(parentComponent, resources.getString("Could not set temporary copy of database to readonly mode.") + "\n" + e, "HSQLDB", |
||||||
Class.forName("org.hsqldb.jdbcDriver"); |
JOptionPane.WARNING_MESSAGE); |
||||||
path = getAdaptedPath(path); |
throw e; |
||||||
|
} |
||||||
int tmpInstanceNumber = checkNumber(path, databasename); |
} |
||||||
|
String url = "jdbc:hsqldb:file:" + path + databasename + "_TMP_COPY" + tmpInstanceNumber; |
||||||
try { |
|
||||||
copyDatabaseFiles(path, databasename, tmpInstanceNumber); |
Connection con = java.sql.DriverManager.getConnection(url, username, password); |
||||||
} catch (IOException e) { |
|
||||||
JOptionPane.showMessageDialog(parentComponent, resources |
if (!isReadOnlyCopyWanted) { |
||||||
.getString("Could not create temporary copy of database.)") |
Statement stmt = con.createStatement(); |
||||||
+ "\n" + e, "HSQLDB", JOptionPane.WARNING_MESSAGE); |
ResultSet rs = stmt.executeQuery("select count(*) from system_tables where hsqldb_type='TEXT'"); |
||||||
throw e; |
rs.next(); |
||||||
} |
if (rs.getInt(1) > 0) { |
||||||
|
stmt.execute("shutdown"); |
||||||
if (isReadOnlyCopyWanted) { |
stmt.close(); |
||||||
try { |
con.close(); |
||||||
setReadonly(path + databasename + "_TMP_COPY" |
deleteTmpFiles(url, path, databasename); |
||||||
+ tmpInstanceNumber + ".properties"); |
throw new SQLException(resources.getString("Handling non read-only temporary database with text tables is not supported")); |
||||||
} catch (IOException e) { |
} |
||||||
JOptionPane |
rs.close(); |
||||||
.showMessageDialog( |
stmt.close(); |
||||||
parentComponent, |
} |
||||||
resources |
return con; |
||||||
.getString("Could not set temporary copy of database to readonly mode.") |
} |
||||||
+ "\n" + e, "HSQLDB", |
|
||||||
JOptionPane.WARNING_MESSAGE); |
private static int checkNumber(String path, String databasename) { |
||||||
throw e; |
int result = 1; |
||||||
} |
while (new File(path + databasename + "_TMP_COPY" + result + ".script").exists()) |
||||||
} |
result++; |
||||||
String url = "jdbc:hsqldb:file:" + path + databasename |
return result; |
||||||
+ "_TMP_COPY" + tmpInstanceNumber; |
} |
||||||
|
|
||||||
Connection con = java.sql.DriverManager.getConnection(url, username, |
/** |
||||||
password); |
* Returns a regular connection to a database and creates a file |
||||||
|
* database_user.properties with the name of the user that opens the |
||||||
if (!isReadOnlyCopyWanted) { |
* database |
||||||
Statement stmt = con.createStatement(); |
* |
||||||
ResultSet rs = stmt |
* @param String |
||||||
.executeQuery("select count(*) from system_tables where hsqldb_type='TEXT'"); |
* path - null,"" or "." for current dir |
||||||
rs.next(); |
* @param String |
||||||
if (rs.getInt(1) > 0) { |
* databasename |
||||||
stmt.execute("shutdown"); |
* @param String |
||||||
stmt.close(); |
* username |
||||||
con.close(); |
* @param String |
||||||
deleteTmpFiles(url, path, databasename); |
* password |
||||||
throw new SQLException( |
* @return Connection to the database |
||||||
resources |
* @throws ClassNotFoundException |
||||||
.getString("Handling non read-only temporary database with text tables is not supported")); |
* @throws SQLException |
||||||
} |
* @throws IOException |
||||||
rs.close(); |
*/ |
||||||
stmt.close(); |
public static Connection getConnection(String path, String databasename, String username, String password) throws ClassNotFoundException, SQLException, IOException { |
||||||
} |
Class.forName("org.hsqldb.jdbcDriver"); |
||||||
return con; |
String url = null; |
||||||
} |
if (path == null) |
||||||
|
url = "jdbc:hsqldb:" + databasename; |
||||||
private static int checkNumber(String path, String databasename) { |
else |
||||||
int result = 1; |
url = "jdbc:hsqldb:file:" + getAdaptedPath(path) + databasename; |
||||||
while (new File(path + databasename + "_TMP_COPY" + result |
|
||||||
+ ".script").exists()) |
Connection con = java.sql.DriverManager.getConnection(url, username, password); |
||||||
result++; |
|
||||||
return result; |
Properties p = new Properties(); |
||||||
} |
p.put("user", System.getProperty("user.name")); |
||||||
|
String filename = (path != null ? path + "/" + databasename + "_user.properties" : databasename + "_user.properties"); |
||||||
/** |
FileOutputStream fos = new FileOutputStream(filename); |
||||||
* Returns a regular connection to a database and creates a file |
p.store(fos, "User which uses the HSQL database"); |
||||||
* database_user.properties with the name of the user that opens the |
fos.close(); |
||||||
* database |
|
||||||
* |
return con; |
||||||
* @param String |
} |
||||||
* path - null,"" or "." for current dir |
|
||||||
* @param String |
/** |
||||||
* databasename |
* String and makes sure separator char is at the end |
||||||
* @param String |
* |
||||||
* username |
* @param String |
||||||
* @param String |
* path |
||||||
* password |
* @return adapted path String |
||||||
* @return Connection to the database |
*/ |
||||||
* @throws ClassNotFoundException |
private static String getAdaptedPath(String path) { |
||||||
* @throws SQLException |
if (path == null) path = ""; |
||||||
* @throws IOException |
if ((path.equals(".") || path.length() > 1) && !(path.endsWith("/") || path.endsWith("\\"))) path += File.separator; |
||||||
*/ |
|
||||||
public static Connection getConnection(String path, String databasename, |
return path; |
||||||
String username, String password) throws ClassNotFoundException, |
} |
||||||
SQLException, IOException { |
|
||||||
Class.forName("org.hsqldb.jdbcDriver"); |
/** |
||||||
String url=null; |
* Changes the property readonly to true in a database properties file |
||||||
if (path==null) |
* |
||||||
url="jdbc:hsqldb:"+databasename; |
* @param String |
||||||
else |
* propertiesFile including path if necessary |
||||||
url = "jdbc:hsqldb:file:" + getAdaptedPath(path) + databasename; |
* @throws IOException |
||||||
|
*/ |
||||||
Connection con = java.sql.DriverManager.getConnection(url, username, |
private static void setReadonly(String propertiesFile) throws IOException { |
||||||
password); |
Properties p = new Properties(); |
||||||
|
p.load(new FileInputStream(propertiesFile)); |
||||||
Properties p = new Properties(); |
p.put("readonly", "true"); |
||||||
p.put("user", System.getProperty("user.name")); |
p.store(new FileOutputStream(propertiesFile), "HSQL database"); |
||||||
String filename=(path!=null?path+"/"+databasename+"_user.properties":databasename+"_user.properties"); |
|
||||||
FileOutputStream fos = new FileOutputStream(filename); |
} |
||||||
p.store(fos, "User which uses the HSQL database"); |
|
||||||
fos.close(); |
/** |
||||||
|
* Makes a temporary copy of all existing database files with the appendix |
||||||
return con; |
* _TMP_COPY |
||||||
} |
* |
||||||
|
* @param String |
||||||
/** |
* path - may be null for current dir, no / or \ at the end |
||||||
* String and makes sure separator char is at the end |
* @param String |
||||||
* |
* databasename |
||||||
* @param String |
* @throws IOException |
||||||
* path |
*/ |
||||||
* @return adapted path String |
private static void copyDatabaseFiles(String path, String databasename, int number) throws IOException { |
||||||
*/ |
|
||||||
private static String getAdaptedPath(String path) { |
String s = path + databasename; |
||||||
if (path == null) path = ""; |
copyFile(s + ".script", s + "_TMP_COPY" + number + ".script"); |
||||||
if ((path.equals(".")||path.length()>1)&&!(path.endsWith("/")||path.endsWith("\\"))) |
copyFile(s + ".properties", s + "_TMP_COPY" + number + ".properties"); |
||||||
path+=File.separator; |
if (new File(s + ".log").exists()) copyFile(s + ".log", s + "_TMP_COPY" + number + ".log"); |
||||||
|
if (new File(s + ".data").exists()) copyFile(s + ".data", s + "_TMP_COPY" + number + ".data"); |
||||||
return path; |
if (new File(s + ".backup").exists()) copyFile(s + ".backup", s + "_TMP_COPY" + number + ".backup"); |
||||||
} |
if (new File(s + ".nio").exists()) copyFile(s + ".nio", s + "_TMP_COPY" + number + ".nio"); |
||||||
|
} |
||||||
/** |
|
||||||
* Changes the property readonly to true in a database properties file |
/** |
||||||
* |
* Creates a copy of a file |
||||||
* @param String |
* |
||||||
* propertiesFile including path if necessary |
* @param String |
||||||
* @throws IOException |
* source - source file name (incl. path if necessary) |
||||||
*/ |
* @param String |
||||||
private static void setReadonly(String propertiesFile) throws IOException { |
* target - target file name (incl. path if necessary) |
||||||
Properties p = new Properties(); |
* @throws IOException |
||||||
p.load(new FileInputStream(propertiesFile)); |
*/ |
||||||
p.put("readonly", "true"); |
static public void copyFile(String source, String target) throws IOException { |
||||||
p.store(new FileOutputStream(propertiesFile), "HSQL database"); |
|
||||||
|
try { |
||||||
} |
FileInputStream is = new FileInputStream(source); |
||||||
|
FileOutputStream os = new FileOutputStream(target); |
||||||
/** |
|
||||||
* Makes a temporary copy of all existing database files with the appendix |
BufferedInputStream in = new BufferedInputStream(is); |
||||||
* _TMP_COPY |
BufferedOutputStream out = new BufferedOutputStream(os); |
||||||
* |
|
||||||
* @param String |
int buffer_size = 32768; |
||||||
* path - may be null for current dir, no / or \ at the end |
byte[] buffer = new byte[buffer_size]; |
||||||
* @param String |
|
||||||
* databasename |
int len = in.read(buffer, 0, buffer_size); |
||||||
* @throws IOException |
while (len != -1) { |
||||||
*/ |
out.write(buffer, 0, len); |
||||||
private static void copyDatabaseFiles(String path, String databasename, |
len = in.read(buffer, 0, buffer_size); |
||||||
int number) throws IOException { |
} |
||||||
|
in.close(); |
||||||
String s = path + databasename; |
is.close(); |
||||||
copyFile(s + ".script", s + "_TMP_COPY" + number + ".script"); |
out.close(); |
||||||
copyFile(s + ".properties", s + "_TMP_COPY" + number + ".properties"); |
os.close(); |
||||||
if (new File(s + ".log").exists()) |
|
||||||
copyFile(s + ".log", s + "_TMP_COPY" + number + ".log"); |
} catch (IOException e) { |
||||||
if (new File(s + ".data").exists()) |
throw new IOException("Couldn't copy file " + source + ": " + e.toString()); |
||||||
copyFile(s + ".data", s + "_TMP_COPY" + number + ".data"); |
} |
||||||
if (new File(s + ".backup").exists()) |
} |
||||||
copyFile(s + ".backup", s + "_TMP_COPY" + number + ".backup"); |
|
||||||
if (new File(s + ".nio").exists()) |
private static class TmpFileFilter implements FilenameFilter { |
||||||
copyFile(s + ".nio", s + "_TMP_COPY" + number + ".nio"); |
private String tmpName; |
||||||
} |
|
||||||
|
TmpFileFilter(String tmpName) { |
||||||
/** |
this.tmpName = tmpName; |
||||||
* Creates a copy of a file |
} |
||||||
* |
|
||||||
* @param String |
@Override |
||||||
* source - source file name (incl. path if necessary) |
public boolean accept(File dir, String name) { |
||||||
* @param String |
return name.indexOf(tmpName) > -1; |
||||||
* target - target file name (incl. path if necessary) |
} |
||||||
* @throws IOException |
|
||||||
*/ |
} |
||||||
static public void copyFile(String source, String target) |
|
||||||
throws IOException { |
} |
||||||
|
|
||||||
try { |
//Created on 21.10.2004 at 20:35:55
|
||||||
FileInputStream is = new FileInputStream(source); |
|
||||||
FileOutputStream os = new FileOutputStream(target); |
|
||||||
|
|
||||||
BufferedInputStream in = new BufferedInputStream(is); |
|
||||||
BufferedOutputStream out = new BufferedOutputStream(os); |
|
||||||
|
|
||||||
int buffer_size = 32768; |
|
||||||
byte[] buffer = new byte[buffer_size]; |
|
||||||
|
|
||||||
int len = in.read(buffer, 0, buffer_size); |
|
||||||
while (len != -1) { |
|
||||||
out.write(buffer, 0, len); |
|
||||||
len = in.read(buffer, 0, buffer_size); |
|
||||||
} |
|
||||||
in.close(); |
|
||||||
is.close(); |
|
||||||
out.close(); |
|
||||||
os.close(); |
|
||||||
|
|
||||||
} catch (IOException e) { |
|
||||||
throw new IOException("Couldn't copy file " + source + ": " |
|
||||||
+ e.toString()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private static class TmpFileFilter implements FilenameFilter { |
|
||||||
private String tmpName; |
|
||||||
|
|
||||||
TmpFileFilter(String tmpName) { |
|
||||||
this.tmpName = tmpName; |
|
||||||
} |
|
||||||
|
|
||||||
public boolean accept(File dir, String name) { |
|
||||||
return name.indexOf(tmpName) > -1; |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
//Created on 21.10.2004 at 20:35:55
|
|
||||||
|
|||||||
@ -1,70 +1,66 @@ |
|||||||
/* |
/* |
||||||
* Copyright (c) 2001-2004, The HSQL Development Group All rights reserved. |
* Copyright (c) 2001-2004, The HSQL Development Group All rights reserved. |
||||||
* |
* |
||||||
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
||||||
* modification, are permitted provided that the following conditions are met: |
* modification, are permitted provided that the following conditions are met: |
||||||
* |
* |
||||||
* Redistributions of source code must retain the above copyright notice, this |
* Redistributions of source code must retain the above copyright notice, this |
||||||
* list of conditions and the following disclaimer. |
* list of conditions and the following disclaimer. |
||||||
* |
* |
||||||
* Redistributions in binary form must reproduce the above copyright notice, |
* Redistributions in binary form must reproduce the above copyright notice, |
||||||
* this list of conditions and the following disclaimer in the documentation |
* this list of conditions and the following disclaimer in the documentation |
||||||
* and/or other materials provided with the distribution. |
* and/or other materials provided with the distribution. |
||||||
* |
* |
||||||
* Neither the name of the HSQL Development Group nor the names of its |
* Neither the name of the HSQL Development Group nor the names of its |
||||||
* contributors may be used to endorse or promote products derived from this |
* contributors may be used to endorse or promote products derived from this |
||||||
* software without specific prior written permission. |
* software without specific prior written permission. |
||||||
* |
* |
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG, OR |
* ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG, OR |
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
||||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
||||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
||||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
||||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||||
*/ |
*/ |
||||||
|
|
||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
/** |
|
||||||
* Resources for HsqlStandaloneMgr. |
/** |
||||||
* For other locales extend AbstractHsqlStandloneMgrResources, i.e. |
* Resources for HsqlStandaloneMgr. |
||||||
* by copying HsqlStandaloneMgrResources_de to your locale |
* For other locales extend AbstractHsqlStandloneMgrResources, i.e. |
||||||
*/ |
* by copying HsqlStandaloneMgrResources_de to your locale |
||||||
|
*/ |
||||||
public class HsqlStandaloneMgrResources extends |
|
||||||
AbstractHsqlStandaloneMgrResources { |
public class HsqlStandaloneMgrResources extends AbstractHsqlStandaloneMgrResources { |
||||||
public Object[][] getContents() { |
@Override |
||||||
return contents; |
public Object[][] getContents() { |
||||||
} |
return contents; |
||||||
|
} |
||||||
static final Object[][] contents = { |
|
||||||
|
static final Object[][] contents = { |
||||||
{ "Couldn't read user name", "Couldn't read user name" }, |
|
||||||
{ "Would you like to open a temporary copy in read-only mode?", |
{ "Couldn't read user name", "Couldn't read user name" }, |
||||||
"Would you like to open a temporary copy in read-only mode?" }, |
{ "Would you like to open a temporary copy in read-only mode?", "Would you like to open a temporary copy in read-only mode?" }, |
||||||
{ |
{ "Would you like to open a temporary copy?\nAttention - any changes to the database will be lost after closing the program!", |
||||||
"Would you like to open a temporary copy?\nAttention - any changes to the database will be lost after closing the program!", |
"Would you like to open a temporary copy?\nAttention - any changes to the database will be lost after closing the program!" }, |
||||||
"Would you like to open a temporary copy?\nAttention - any changes to the database will be lost after closing the program!" }, |
{ "Could not create temporary copy of database.", "Could not create temporary copy of database." }, |
||||||
{ "Could not create temporary copy of database.", |
{ "Could not set temporary copy of database to readonly mode.", "Could not set temporary copy of database to readonly mode." }, |
||||||
"Could not create temporary copy of database." }, |
{ "Handling non read-only temporary database with text tables is not supported", |
||||||
{ "Could not set temporary copy of database to readonly mode.", |
"Handling non read-only temporary database with text tables is not supported" } |
||||||
"Could not set temporary copy of database to readonly mode." }, |
|
||||||
{ |
}; |
||||||
"Handling non read-only temporary database with text tables is not supported", |
|
||||||
"Handling non read-only temporary database with text tables is not supported" } |
@Override |
||||||
|
public String getDbInUseBy(String dbname, String user) { |
||||||
}; |
String result = "The database " + dbname + " is already in use"; |
||||||
|
if (user != null) result += " by user " + user; |
||||||
public String getDbInUseBy(String dbname, String user) { |
result += ".\n"; |
||||||
String result = "The database " + dbname + " is already in use"; |
return result; |
||||||
if (user != null) |
} |
||||||
result += " by user " + user; |
} |
||||||
result += ".\n"; |
|
||||||
return result; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|||||||
@ -1,68 +1,63 @@ |
|||||||
/* |
/* |
||||||
* Copyright (c) 2001-2004, The HSQL Development Group All rights reserved. |
* Copyright (c) 2001-2004, The HSQL Development Group All rights reserved. |
||||||
* |
* |
||||||
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
||||||
* modification, are permitted provided that the following conditions are met: |
* modification, are permitted provided that the following conditions are met: |
||||||
* |
* |
||||||
* Redistributions of source code must retain the above copyright notice, this |
* Redistributions of source code must retain the above copyright notice, this |
||||||
* list of conditions and the following disclaimer. |
* list of conditions and the following disclaimer. |
||||||
* |
* |
||||||
* Redistributions in binary form must reproduce the above copyright notice, |
* Redistributions in binary form must reproduce the above copyright notice, |
||||||
* this list of conditions and the following disclaimer in the documentation |
* this list of conditions and the following disclaimer in the documentation |
||||||
* and/or other materials provided with the distribution. |
* and/or other materials provided with the distribution. |
||||||
* |
* |
||||||
* Neither the name of the HSQL Development Group nor the names of its |
* Neither the name of the HSQL Development Group nor the names of its |
||||||
* contributors may be used to endorse or promote products derived from this |
* contributors may be used to endorse or promote products derived from this |
||||||
* software without specific prior written permission. |
* software without specific prior written permission. |
||||||
* |
* |
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG, OR |
* ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG, OR |
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
||||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
||||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
||||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
||||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||||
*/ |
*/ |
||||||
|
|
||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
/** |
|
||||||
* Resources for HsqlStandaloneMgr. |
/** |
||||||
* For other locales extend AbstractHsqlStandloneMgrResources, i.e. |
* Resources for HsqlStandaloneMgr. |
||||||
* by copying this class to your locale |
* For other locales extend AbstractHsqlStandloneMgrResources, i.e. |
||||||
*/ |
* by copying this class to your locale |
||||||
public class HsqlStandaloneMgrResources_de extends |
*/ |
||||||
AbstractHsqlStandaloneMgrResources { |
public class HsqlStandaloneMgrResources_de extends AbstractHsqlStandaloneMgrResources { |
||||||
public Object[][] getContents() { |
@Override |
||||||
return contents; |
public Object[][] getContents() { |
||||||
} |
return contents; |
||||||
|
} |
||||||
static final Object[][] contents = { |
|
||||||
{ "Couldn't read user name", "Konnte Usernamen nicht lesen" }, |
static final Object[][] contents = { { "Couldn't read user name", "Konnte Usernamen nicht lesen" }, |
||||||
{ "Would you like to open a temporary copy in read-only mode?", |
{ "Would you like to open a temporary copy in read-only mode?", "Möchten Sie eine schreibgeschützte Kopie öffnen?" }, |
||||||
"Möchten Sie eine schreibgeschützte Kopie öffnen?" }, |
{ "Would you like to open a temporary copy?\nAttention - any changes to the database will be lost after closing the program!", |
||||||
{ |
"Möchten Sie eine temporäre Kopie öffnen?\nAchtung, wenn Sie das Programm beenden, gehen alle Änderungen, die Sie vorgenommen haben, verloren!" }, |
||||||
"Would you like to open a temporary copy?\nAttention - any changes to the database will be lost after closing the program!", |
{ "Could not create temporary copy of database.", "Konnte keine temporäre Kopie der Datenbank anlegen." }, |
||||||
"Möchten Sie eine temporäre Kopie öffnen?\nAchtung, wenn Sie das Programm beenden, gehen alle Änderungen, die Sie vorgenommen haben, verloren!" }, |
{ "Could not set temporary copy of database to readonly mode.", "Konnte die temp. Kopie nicht auf schreibgeschützt setzen" }, |
||||||
{ "Could not create temporary copy of database.", |
{ "Handling non read-only temporary database with text tables is not supported", |
||||||
"Konnte keine temporäre Kopie der Datenbank anlegen." }, |
"Nicht schreibgeschützte Datenbanken mit Text-Tables werden nicht unterstützt" } |
||||||
{ "Could not set temporary copy of database to readonly mode.", |
|
||||||
"Konnte die temp. Kopie nicht auf schreibgeschützt setzen" }, |
}; |
||||||
{ |
|
||||||
"Handling non read-only temporary database with text tables is not supported", |
@Override |
||||||
"Nicht schreibgeschützte Datenbanken mit Text-Tables werden nicht unterstützt" } |
public String getDbInUseBy(String dbname, String user) { |
||||||
|
String result = "Die Datenbank " + dbname + " wird schon benutzt "; |
||||||
}; |
if (user != null) result += " vom User " + user; |
||||||
|
result += ".\n"; |
||||||
public String getDbInUseBy(String dbname, String user) { |
return result; |
||||||
String result = "Die Datenbank " + dbname + " wird schon benutzt "; |
} |
||||||
if (user != null) |
} |
||||||
result += " vom User " + user; |
|
||||||
result += ".\n"; |
|
||||||
return result; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|||||||
@ -1,91 +1,83 @@ |
|||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import java.sql.Connection; |
import java.sql.Connection; |
||||||
import java.sql.ResultSet; |
import java.sql.ResultSet; |
||||||
import java.sql.SQLException; |
import java.sql.SQLException; |
||||||
import java.sql.Statement; |
import java.sql.Statement; |
||||||
/** |
|
||||||
* Additional procedures for HSQLDB |
/** |
||||||
* make sure that this class in the classpath. |
* Additional procedures for HSQLDB |
||||||
* To constantly add it to hsql, go to the directory where your hsqldb.jar is located |
* make sure that this class in the classpath. |
||||||
* Call jar -xf hsqlAddOn.jar |
* To constantly add it to hsql, go to the directory where your hsqldb.jar is located |
||||||
* jar -uf hsqldb.jar org/hsqldb/Library2.class |
* Call jar -xf hsqlAddOn.jar |
||||||
* Delete the directory org. |
* jar -uf hsqldb.jar org/hsqldb/Library2.class |
||||||
* |
* Delete the directory org. |
||||||
* Open your Database in Database Manager and execute |
* |
||||||
* the following commands once: |
* Open your Database in Database Manager and execute |
||||||
* GRANT ALL ON CLASS "org.hsqldb.Library2" TO PUBLIC and |
* the following commands once: |
||||||
* CREATE ALIAS COPYFROM FOR "org.hsqldb.Library2.copyFrom" |
* GRANT ALL ON CLASS "org.hsqldb.Library2" TO PUBLIC and |
||||||
*/ |
* CREATE ALIAS COPYFROM FOR "org.hsqldb.Library2.copyFrom" |
||||||
public class Library2 { |
*/ |
||||||
private Library2() { |
public class Library2 { |
||||||
super(); |
private Library2() { |
||||||
} |
super(); |
||||||
/** |
} |
||||||
* Fills regular tables with values from a CSV-file. |
|
||||||
* Similar to Postgres COPY FROM command. |
/** |
||||||
* |
* Fills regular tables with values from a CSV-file. |
||||||
* If you want to fill your table TEST with data from test.csv |
* Similar to Postgres COPY FROM command. |
||||||
* make sure that this class in the classpath and that |
* |
||||||
* GRANT ALL ON CLASS "org.hsqldb.Library2" TO PUBLIC and |
* If you want to fill your table TEST with data from test.csv |
||||||
* CREATE ALIAS COPYFROM FOR "org.hsqldb.Library2.copyFrom" |
* make sure that this class in the classpath and that |
||||||
* has been called in your database at some point. |
* GRANT ALL ON CLASS "org.hsqldb.Library2" TO PUBLIC and |
||||||
|
* CREATE ALIAS COPYFROM FOR "org.hsqldb.Library2.copyFrom" |
||||||
* * Then execute |
* has been called in your database at some point. |
||||||
* COPYFROM("TEST","test.csv",null) |
|
||||||
* |
* * Then execute |
||||||
* if your not using , but | as a field separator |
* COPYFROM("TEST","test.csv",null) |
||||||
COPYFROM("TEST","test.csv","fs=|") |
* |
||||||
|
* if your not using , but | as a field separator |
||||||
* |
COPYFROM("TEST","test.csv","fs=|") |
||||||
* @param con - Connection is automatically handed over by HSQL |
|
||||||
* @param table - the name of the table that is to be filled |
* |
||||||
* if your table isn't found capital letters may be required |
* @param con - Connection is automatically handed over by HSQL |
||||||
* @param file - the filename of the CSV-file |
* @param table - the name of the table that is to be filled |
||||||
* @param options - you can specify options separated by ; |
* if your table isn't found capital letters may be required |
||||||
* which are described in the text table documentation e.g. |
* @param file - the filename of the CSV-file |
||||||
* fs=| to use pipe instead of default comma as field separator or |
* @param options - you can specify options separated by ; |
||||||
* or |
* which are described in the text table documentation e.g. |
||||||
* fs=|;vs=.;lvs=~" varchar separator, longvarchar separator |
* fs=| to use pipe instead of default comma as field separator or |
||||||
* ignore_first=true; ignore first line |
* or |
||||||
* all_quoted=true or |
* fs=|;vs=.;lvs=~" varchar separator, longvarchar separator |
||||||
* encoding=UTF-8 if you don't have ASCII |
* ignore_first=true; ignore first line |
||||||
* @throws SQLException |
* all_quoted=true or |
||||||
*/ |
* encoding=UTF-8 if you don't have ASCII |
||||||
public static void copyFrom( |
* @throws SQLException |
||||||
Connection con, |
*/ |
||||||
String table, |
public static void copyFrom(Connection con, String table, String file, String options) throws SQLException { |
||||||
String file, |
StringBuffer buf = new StringBuffer("create text table TMP_SOURCE_" + table + " ("); |
||||||
String options) |
|
||||||
throws SQLException { |
ResultSet rs = con.getMetaData().getColumns(null, null, table, null); |
||||||
StringBuffer buf = |
String colname, coltype; |
||||||
new StringBuffer("create text table TMP_SOURCE_" + table + " ("); |
boolean tableFound = false; |
||||||
|
while (rs.next()) { |
||||||
ResultSet rs = con.getMetaData().getColumns(null, null, table, null); |
tableFound = true; |
||||||
String colname, coltype; |
colname = rs.getObject(4).toString(); |
||||||
boolean tableFound = false; |
coltype = rs.getObject(6).toString(); |
||||||
while (rs.next()) { |
buf.append(colname + " " + coltype + ","); |
||||||
tableFound = true; |
} |
||||||
colname = rs.getObject(4).toString(); |
rs.close(); |
||||||
coltype = rs.getObject(6).toString(); |
if (!tableFound) throw new IllegalArgumentException("Copy from failed - table " + table + " not found"); |
||||||
buf.append(colname + " " + coltype + ","); |
buf.deleteCharAt(buf.lastIndexOf(",")); |
||||||
} |
buf.append("); SET TABLE TMP_SOURCE_" + table + " SOURCE \"" + file); |
||||||
rs.close(); |
if (options != null) buf.append(";" + options); |
||||||
if (!tableFound) |
buf.append("\";"); |
||||||
throw new IllegalArgumentException( |
buf.append("insert into " + table + " select * from TMP_SOURCE_" + table); |
||||||
"Copy from failed - table " + table + " not found"); |
Statement stmt = con.createStatement(); |
||||||
buf.deleteCharAt(buf.lastIndexOf(",")); |
try { |
||||||
buf.append("); SET TABLE TMP_SOURCE_" + table + " SOURCE \"" + file); |
stmt.execute(buf.toString()); |
||||||
if (options != null) |
} finally { |
||||||
buf.append(";" + options); |
stmt.execute("drop table TMP_SOURCE_" + table + " IF EXISTS"); |
||||||
buf.append("\";"); |
} |
||||||
buf.append( |
} |
||||||
"insert into " + table + " select * from TMP_SOURCE_" + table); |
} |
||||||
Statement stmt = con.createStatement(); |
|
||||||
try { |
|
||||||
stmt.execute(buf.toString()); |
|
||||||
} finally { |
|
||||||
stmt.execute("drop table TMP_SOURCE_" + table + " IF EXISTS"); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|||||||
@ -1,262 +0,0 @@ |
|||||||
package de.memtext.db; |
|
||||||
|
|
||||||
import java.io.File; |
|
||||||
import java.io.IOException; |
|
||||||
import java.security.InvalidKeyException; |
|
||||||
import java.security.NoSuchAlgorithmException; |
|
||||||
import java.security.SignatureException; |
|
||||||
import java.security.spec.InvalidKeySpecException; |
|
||||||
import java.sql.Connection; |
|
||||||
import java.sql.DriverManager; |
|
||||||
import java.sql.ResultSet; |
|
||||||
import java.sql.SQLException; |
|
||||||
import java.sql.Statement; |
|
||||||
import java.util.Properties; |
|
||||||
|
|
||||||
import javax.xml.transform.TransformerConfigurationException; |
|
||||||
|
|
||||||
import org.apache.commons.dbcp.ConnectionFactory; |
|
||||||
import org.apache.commons.dbcp.DriverManagerConnectionFactory; |
|
||||||
import org.apache.commons.dbcp.PoolableConnectionFactory; |
|
||||||
import org.apache.commons.dbcp.PoolingDriver; |
|
||||||
import org.apache.commons.pool.impl.GenericObjectPool; |
|
||||||
|
|
||||||
import de.memtext.baseobjects.NamedObjectI; |
|
||||||
import de.memtext.tree.KeyParentEqualException; |
|
||||||
import de.memtext.util.DSAHandler; |
|
||||||
|
|
||||||
/** |
|
||||||
* A new Connection pool making use of Jakarta Commons dbcp. |
|
||||||
*/ |
|
||||||
public class MemtextPool extends GenericObjectPool implements NamedObjectI { |
|
||||||
|
|
||||||
private String name, subpath; |
|
||||||
private String nameNoAppendix; |
|
||||||
|
|
||||||
private Properties props = new Properties(); |
|
||||||
private String privateKeyEncoded = null; |
|
||||||
private String publicKeyEncoded = null; |
|
||||||
private DSAHandler dsaHandler; |
|
||||||
|
|
||||||
public MemtextPool(String name, String nameAppendix, String subpath) |
|
||||||
throws SQLException, IOException, DBServletException { |
|
||||||
this.subpath = subpath; |
|
||||||
nameNoAppendix = name; |
|
||||||
this.setName(name + nameAppendix); |
|
||||||
try { |
|
||||||
readPropertiesAndUrl(); |
|
||||||
System.out |
|
||||||
.print(" (" + props.getProperty("connectionURL") + ") .."); |
|
||||||
} catch (Exception e) { |
|
||||||
System.out |
|
||||||
.println("Konnte properties / Passwort nicht lesen. " + e); |
|
||||||
e.printStackTrace(); |
|
||||||
throw new DBServletException( |
|
||||||
"Konnte properties / Passwort nicht lesen. " + e); |
|
||||||
} |
|
||||||
try { |
|
||||||
|
|
||||||
Class.forName(props.getProperty("driverName")); |
|
||||||
} catch (ClassNotFoundException e1) { |
|
||||||
throw new DBServletException("Treiber " |
|
||||||
+ props.getProperty("driverName") |
|
||||||
+ " nicht gefunden. Ggfs. nach tomcat/common/lib kopieren."); |
|
||||||
} |
|
||||||
|
|
||||||
initLogging(); |
|
||||||
this.setTestOnBorrow(true); |
|
||||||
|
|
||||||
int minIdle = 5; |
|
||||||
if (props.getProperty("minIdle") != null |
|
||||||
&& !props.getProperty("minIdle").trim().equals("")) { |
|
||||||
minIdle = Integer.parseInt(props.getProperty("minIdle")); |
|
||||||
} |
|
||||||
this.setMinIdle(minIdle); |
|
||||||
int maxIdle = -1; |
|
||||||
if (props.getProperty("maxIdle") != null |
|
||||||
&& !props.getProperty("maxIdle").trim().equals("")) { |
|
||||||
maxIdle = Integer.parseInt(props.getProperty("maxIdle")); |
|
||||||
} |
|
||||||
if (maxIdle != -1) |
|
||||||
setMaxIdle(maxIdle); |
|
||||||
|
|
||||||
int maxActive = -1; |
|
||||||
if (props.getProperty("maxActive") != null |
|
||||||
&& !props.getProperty("maxActive").trim().equals("")) { |
|
||||||
maxActive = Integer.parseInt(props.getProperty("maxActive")); |
|
||||||
} |
|
||||||
if (maxActive != -1) |
|
||||||
setMaxActive(maxActive); |
|
||||||
|
|
||||||
ConnectionFactory connectionFactory = new DriverManagerConnectionFactory( |
|
||||||
props.getProperty("connectionURL"), props); |
|
||||||
PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory( |
|
||||||
connectionFactory, this, null, "select count(*) from xdummy;" //validationQuery
|
|
||||||
, false, true); |
|
||||||
int i = 1; |
|
||||||
try { |
|
||||||
// PoolingDriver driver = new PoolingDriver();
|
|
||||||
Class.forName("org.apache.commons.dbcp.PoolingDriver"); |
|
||||||
} catch (ClassNotFoundException e2) { |
|
||||||
throw new DBServletException( |
|
||||||
"ConnectionPool Klasse org.apache.commons.dbcp.PoolingDriver nicht gefunden.\ncommons-dbcp nach tomcat/common/lib stellen."); |
|
||||||
} |
|
||||||
PoolingDriver driver = (PoolingDriver) DriverManager |
|
||||||
.getDriver("jdbc:apache:commons:dbcp:"); |
|
||||||
|
|
||||||
driver.registerPool(this.getName(), this); |
|
||||||
|
|
||||||
Object x = driver.getConnectionPool(this.getName()); |
|
||||||
try { |
|
||||||
Connection con = this.getConnection(); |
|
||||||
Statement st = con.createStatement(); |
|
||||||
ResultSet rs = st |
|
||||||
.executeQuery("select value from properties where name='privatekey'"); |
|
||||||
while (rs.next()) { |
|
||||||
privateKeyEncoded = rs.getString(1); |
|
||||||
} |
|
||||||
rs.close(); |
|
||||||
rs = st |
|
||||||
.executeQuery("select value from properties where name='publickey'"); |
|
||||||
while (rs.next()) { |
|
||||||
publicKeyEncoded = rs.getString(1); |
|
||||||
} |
|
||||||
rs.close(); |
|
||||||
st.close(); |
|
||||||
con.close(); |
|
||||||
|
|
||||||
} catch (SQLException e) { |
|
||||||
String msg = "Fehler beim Aufbau des ConnectionPools "; |
|
||||||
if (!getName().startsWith("default")) |
|
||||||
msg += " für Mandant: " + getName(); |
|
||||||
msg += "\nKonnte keine Connection aus dem Pool holen.\n" + e; |
|
||||||
|
|
||||||
throw new SQLException(msg); |
|
||||||
} |
|
||||||
if (privateKeyEncoded != null) |
|
||||||
initDSAHandler(); |
|
||||||
} |
|
||||||
|
|
||||||
protected void initLogging() throws IOException { |
|
||||||
/* |
|
||||||
* LogUtils.initRawFile("superx_" + getName(), getLogDir() + "/superx_" + |
|
||||||
* name + ".log", 2000, 1, false, true); LogUtils.initRawFile("superx_" + |
|
||||||
* getName() + "_xml", getLogDir() + "/superx_" + name + "_xml.log", |
|
||||||
* 2000, 1, false, true); |
|
||||||
* |
|
||||||
* Level lev = Level.SEVERE; |
|
||||||
* |
|
||||||
* try { if (props.getProperty("logLevelSQL") != null) lev = |
|
||||||
* Level.parse(props.getProperty("logLevelSQL")); } catch |
|
||||||
* (IllegalArgumentException e) { String msg = "Ungültiger Level für |
|
||||||
* sqlLogger "; if (!this.getName().equals("default")) msg += "(Mandant :" + |
|
||||||
* getName() + ") "; msg += " :" + props.getProperty("logLevelSQL"); |
|
||||||
* System.out.println(msg); } Logger.getLogger("superx_" + |
|
||||||
* getName()).setLevel(lev); lev = Level.SEVERE; |
|
||||||
* |
|
||||||
* try { if (props.getProperty("logLevelXML") != null) lev = |
|
||||||
* Level.parse(props.getProperty("logLevelXML")); } catch |
|
||||||
* (IllegalArgumentException e) { String msg = "Ungültiger Level für |
|
||||||
* XMLLogger "; if (!this.getName().equals("default")) msg += "(Mandant :" + |
|
||||||
* getName() + ") "; msg += " :" + props.getProperty("logLevelXML"); |
|
||||||
* System.out.println(msg); } Logger.getLogger("superx_" + getName() + |
|
||||||
* "_xml").setLevel(lev); |
|
||||||
*/ |
|
||||||
} |
|
||||||
|
|
||||||
public static String getLogDir() { |
|
||||||
String tomcat_home = System.getProperty("catalina.home"); //tomcat 4
|
|
||||||
// and 5
|
|
||||||
if (tomcat_home == null) |
|
||||||
tomcat_home = System.getProperty("tomcat.home"); //tomcat 3.x
|
|
||||||
if (tomcat_home == null) |
|
||||||
tomcat_home = "/home/superx/webserver/tomcat"; |
|
||||||
|
|
||||||
return tomcat_home + "/logs"; |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
public Properties getProperties() { |
|
||||||
return props; |
|
||||||
} |
|
||||||
|
|
||||||
private void readPropertiesAndUrl() throws Exception { |
|
||||||
String propname = "db_" + nameNoAppendix + ".properties"; |
|
||||||
if (nameNoAppendix.equals("default")) |
|
||||||
propname = "db.properties"; |
|
||||||
|
|
||||||
java.net.URL url = MemtextPool.class.getProtectionDomain() |
|
||||||
.getCodeSource().getLocation(); |
|
||||||
File myJar = new File(url.getFile()); |
|
||||||
File myPath = new File(myJar.getParent()); |
|
||||||
String pfad = myPath.getParent() + System.getProperty("file.separator"); |
|
||||||
if (subpath != null) |
|
||||||
pfad += subpath + System.getProperty("file.separator"); |
|
||||||
props = PropsReader.prepareProps(new File(pfad + propname)); |
|
||||||
int i = 1; |
|
||||||
} |
|
||||||
|
|
||||||
public String getName() { |
|
||||||
return name; |
|
||||||
} |
|
||||||
|
|
||||||
public void setName(String name) { |
|
||||||
this.name = name; |
|
||||||
} |
|
||||||
|
|
||||||
public void close() throws SQLException { |
|
||||||
PoolingDriver driver = (PoolingDriver) DriverManager |
|
||||||
.getDriver("jdbc:apache:commons:dbcp:"); |
|
||||||
driver.closePool(this.getName()); |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
public Connection getConnection() throws SQLException { |
|
||||||
return DriverManager.getConnection("jdbc:apache:commons:dbcp:" |
|
||||||
+ this.getName()); |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
public void init() throws TransformerConfigurationException, |
|
||||||
KeyParentEqualException, SQLException, DBServletException { |
|
||||||
} |
|
||||||
|
|
||||||
public void clearLogFiles() throws IOException { |
|
||||||
} |
|
||||||
|
|
||||||
private void initDSAHandler() throws DBServletException { |
|
||||||
//privateKey wird ggfs. im Konstruktur bei Connection-Test, public key
|
|
||||||
// aus properties eingelesen
|
|
||||||
if (privateKeyEncoded == null) |
|
||||||
throw new IllegalStateException( |
|
||||||
"privatekey war null - properties-table auf Eintrag überprüfen"); |
|
||||||
if (publicKeyEncoded == null) |
|
||||||
throw new IllegalStateException( |
|
||||||
"publickey war null - properties-table prüfen"); |
|
||||||
try { |
|
||||||
dsaHandler = new DSAHandler(privateKeyEncoded, publicKeyEncoded); |
|
||||||
} catch (Exception e) { |
|
||||||
throw new DBServletException(e.toString()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public boolean hasDSAHandler() { |
|
||||||
return dsaHandler != null; |
|
||||||
} |
|
||||||
|
|
||||||
public boolean verifiy(String data, String signature) |
|
||||||
throws InvalidKeyException, NoSuchAlgorithmException, |
|
||||||
InvalidKeySpecException, SignatureException { |
|
||||||
if (dsaHandler == null) |
|
||||||
throw new IllegalStateException( |
|
||||||
"DSAHandler ist null, public und private key definition prüfen"); |
|
||||||
return dsaHandler.verify(data, signature); |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
public String getPrivateKey() { |
|
||||||
return privateKeyEncoded; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
//Created on 04.11.2004 at 20:18:11 as SxPool
|
|
||||||
@ -1,197 +0,0 @@ |
|||||||
package de.memtext.db; |
|
||||||
|
|
||||||
import java.io.BufferedReader; |
|
||||||
import java.io.File; |
|
||||||
import java.io.FileReader; |
|
||||||
import java.io.IOException; |
|
||||||
import java.lang.reflect.Constructor; |
|
||||||
import java.lang.reflect.InvocationTargetException; |
|
||||||
import java.sql.Connection; |
|
||||||
import java.sql.DriverManager; |
|
||||||
import java.sql.SQLException; |
|
||||||
import java.util.Iterator; |
|
||||||
|
|
||||||
import javax.xml.transform.TransformerConfigurationException; |
|
||||||
|
|
||||||
import org.apache.commons.dbcp.PoolingDriver; |
|
||||||
|
|
||||||
import de.memtext.baseobjects.coll.NamedObjectSet; |
|
||||||
import de.memtext.tree.KeyParentEqualException; |
|
||||||
|
|
||||||
|
|
||||||
public class MemtextPools extends NamedObjectSet { |
|
||||||
|
|
||||||
private NamedObjectSet pools = new NamedObjectSet(); |
|
||||||
|
|
||||||
public MemtextPools() { |
|
||||||
super(); |
|
||||||
} |
|
||||||
|
|
||||||
public synchronized Connection getConnection(String poolname) |
|
||||||
throws SQLException { |
|
||||||
if (pools.size() == 0) |
|
||||||
throw new IllegalStateException("Kein ConnectionPool gefunden."); |
|
||||||
if (!pools.containsItemWithName(poolname)) |
|
||||||
throw new SQLException("Kein ConnectionPool für Mandant:" |
|
||||||
+ poolname + " gefunden"); |
|
||||||
String pooldrv = "jdbc:apache:commons:dbcp:" + poolname; |
|
||||||
if (DriverManager.getDriver(pooldrv) == null) { |
|
||||||
String msg = "Kein ConnectionPool gefunden "; |
|
||||||
if (!poolname.equals("default")) |
|
||||||
msg += " für Mandant " + poolname; |
|
||||||
throw new SQLException(msg); |
|
||||||
} |
|
||||||
return DriverManager.getConnection(pooldrv); |
|
||||||
} |
|
||||||
|
|
||||||
public MemtextPool get(String poolname) { |
|
||||||
if (!pools.containsItemWithName(poolname)) |
|
||||||
throw new IllegalStateException("Kein ConnectionPool (" + poolname |
|
||||||
+ ") vorhanden"); |
|
||||||
return (MemtextPool) pools.getByName(poolname); |
|
||||||
} |
|
||||||
|
|
||||||
/* void initDefaultOnly() throws SQLException, IOException, |
|
||||||
DBServletException { |
|
||||||
pools.add(new MemtextPool("default")); |
|
||||||
} |
|
||||||
*/ |
|
||||||
/** |
|
||||||
* wenn mehrfach benutzt wird (ConnectionPools für SuperX und Joolap) |
|
||||||
* mind ein sollte namensappendix haben, damit unterscheidbar - |
|
||||||
* sonst wird z.B. Pool für joolap "default" von später erzeugten Pool für superx "default" |
|
||||||
* überschrieben! |
|
||||||
*/ |
|
||||||
public void init(String subpath,Class poolclass, String nameAppendix) throws SQLException, IOException, |
|
||||||
DBServletException { |
|
||||||
if (nameAppendix==null) nameAppendix=""; |
|
||||||
Class[] params = new Class[2]; |
|
||||||
params[0] = String.class; |
|
||||||
params[1] = String.class; |
|
||||||
Constructor constructor; |
|
||||||
try { |
|
||||||
constructor = poolclass.getConstructor(params); |
|
||||||
|
|
||||||
String db_extfile = "mandanten.cfg"; |
|
||||||
if (db_extfile.indexOf(File.separator) == -1) { |
|
||||||
java.net.URL url = MemtextPools.class.getProtectionDomain() |
|
||||||
.getCodeSource().getLocation(); |
|
||||||
File myJar = new File(url.getFile()); |
|
||||||
File myPath = new File(myJar.getParent()); |
|
||||||
String pfad = myPath.getParent(); |
|
||||||
if (subpath!=null) pfad+=File.separator+subpath; |
|
||||||
db_extfile = pfad + File.separator+db_extfile; ; |
|
||||||
|
|
||||||
|
|
||||||
} |
|
||||||
File f = new File(db_extfile); |
|
||||||
if (!f.exists()) { |
|
||||||
//einfach nur normale db.properties (default)
|
|
||||||
System.out.print("Aufbau Datenbank-ConnectionPool"); |
|
||||||
Object[] args = new Object[2]; |
|
||||||
args[0] = "default";//Appendix hängt JoolapPool an
|
|
||||||
args[1] = subpath; |
|
||||||
MemtextPool connectionPool = (MemtextPool) constructor.newInstance(args); |
|
||||||
System.out.println(" OK"); |
|
||||||
System.out.println(" public/private key "+(connectionPool.hasDSAHandler()?" aktiv ":" nicht aktiv")); |
|
||||||
|
|
||||||
pools.add(connectionPool); |
|
||||||
} else { //mehrereMandanten
|
|
||||||
FileReader fr = new FileReader(f); |
|
||||||
BufferedReader bfr = new BufferedReader(fr); |
|
||||||
String line; |
|
||||||
while ((line = bfr.readLine()) != null) { |
|
||||||
System.out.print("Aufbau Datenbank-ConnectionPool für " |
|
||||||
+ line); |
|
||||||
Object[] args = new Object[2]; |
|
||||||
args[0] = line;//Appendix hängt JoolapPool an
|
|
||||||
args[1] = subpath; |
|
||||||
MemtextPool connectionPool = (MemtextPool) constructor.newInstance(args); |
|
||||||
System.out.println("OK"); |
|
||||||
System.out.println(" public/private key"+(connectionPool.hasDSAHandler()?" aktiv ":" nicht aktiv")); |
|
||||||
|
|
||||||
pools.add(connectionPool); |
|
||||||
} |
|
||||||
bfr.close(); |
|
||||||
fr.close(); |
|
||||||
} |
|
||||||
} catch (SecurityException e) { |
|
||||||
e.printStackTrace(); |
|
||||||
throw new DBServletException(e.toString()); |
|
||||||
} catch (NoSuchMethodException e) { |
|
||||||
e.printStackTrace(); |
|
||||||
throw new DBServletException(e.toString()); |
|
||||||
} catch (IllegalArgumentException e) { |
|
||||||
e.printStackTrace(); |
|
||||||
throw new DBServletException(e.toString()); |
|
||||||
} catch (InstantiationException e) { |
|
||||||
e.printStackTrace(); |
|
||||||
throw new DBServletException(e.toString()); |
|
||||||
} catch (IllegalAccessException e) { |
|
||||||
e.printStackTrace(); |
|
||||||
throw new DBServletException(e.toString()); |
|
||||||
} catch (InvocationTargetException e) { |
|
||||||
e.printStackTrace(); |
|
||||||
throw new DBServletException(e.toString()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Destroys all ConnectionPools |
|
||||||
* |
|
||||||
* @throws Exception |
|
||||||
*/ |
|
||||||
public void closeAll() throws Exception { |
|
||||||
for (Iterator it = pools.iterator(); it.hasNext();) { |
|
||||||
MemtextPool pool = (MemtextPool) it.next(); |
|
||||||
pool.close(); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
public void main(String args[]) { |
|
||||||
try { |
|
||||||
init("xx",MemtextPool.class, null); |
|
||||||
} catch (Exception e) { |
|
||||||
e.printStackTrace(); |
|
||||||
} |
|
||||||
int i = 1; |
|
||||||
} |
|
||||||
|
|
||||||
public void invalidate(String poolname, Connection con) |
|
||||||
throws DBServletException { |
|
||||||
if (!pools.containsItemWithName(poolname)) |
|
||||||
throw new DBServletException( |
|
||||||
"Kann Connection nicht invalidieren - kein ConnectionPool " |
|
||||||
+ poolname + " gefunden."); |
|
||||||
try { |
|
||||||
PoolingDriver driver = (PoolingDriver) DriverManager |
|
||||||
.getDriver("jdbc:apache:commons:dbcp:"); |
|
||||||
|
|
||||||
//driver.invalidateConnection(con);
|
|
||||||
driver.getConnectionPool(poolname).invalidateObject(con); |
|
||||||
} catch (Exception e) { |
|
||||||
e.printStackTrace(); |
|
||||||
throw new DBServletException("Invalidating connection failed -" + e); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
public void resetAllPools() |
|
||||||
throws TransformerConfigurationException, KeyParentEqualException, |
|
||||||
SQLException, DBServletException { |
|
||||||
for (Iterator it = pools.iterator(); it.hasNext();) { |
|
||||||
MemtextPool aPool = (MemtextPool) it.next(); |
|
||||||
aPool.init(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public void clearLogFiles() throws IOException { |
|
||||||
for (Iterator it = pools.iterator(); it.hasNext();) { |
|
||||||
MemtextPool aPool = (MemtextPool) it.next(); |
|
||||||
aPool.clearLogFiles(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
//Created on 04.11.2004 at 20:18:11 als SxPools
|
|
||||||
@ -1,22 +1,23 @@ |
|||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
public class NichtAngemeldetException extends Exception { |
|
||||||
|
public class NichtAngemeldetException extends Exception { |
||||||
public NichtAngemeldetException() { |
|
||||||
super(); |
public NichtAngemeldetException() { |
||||||
} |
super(); |
||||||
|
} |
||||||
public NichtAngemeldetException(String message) { |
|
||||||
super(message); |
public NichtAngemeldetException(String message) { |
||||||
} |
super(message); |
||||||
|
} |
||||||
public NichtAngemeldetException(String message, Throwable cause) { |
|
||||||
super(message, cause); |
public NichtAngemeldetException(String message, Throwable cause) { |
||||||
} |
super(message, cause); |
||||||
|
} |
||||||
public NichtAngemeldetException(Throwable cause) { |
|
||||||
super(cause); |
public NichtAngemeldetException(Throwable cause) { |
||||||
} |
super(cause); |
||||||
|
} |
||||||
} |
|
||||||
|
} |
||||||
|
|
||||||
//Created on 05.10.2004 at 13:12:23
|
//Created on 05.10.2004 at 13:12:23
|
||||||
@ -1,101 +1,100 @@ |
|||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import de.memtext.util.StringUtils; |
import de.memtext.util.StringUtils; |
||||||
/** |
|
||||||
* Hilfsklasse zum Erstellen von Prozeduraufrüfen für verschd. |
/** |
||||||
* Datenbanken. |
* Hilfsklasse zum Erstellen von Prozeduraufrüfen für verschd. |
||||||
* Wird mit DB Object erstellt, z.B. ProcedureSql(DB.INFORMIX) |
* Datenbanken. |
||||||
* dann setName() |
* Wird mit DB Object erstellt, z.B. ProcedureSql(DB.INFORMIX) |
||||||
* dann beliebig oft addParam(),oder addDateParam() |
* dann setName() |
||||||
* Falls nach Aufruf der Prozedur ein select notwendig ist, |
* dann beliebig oft addParam(),oder addDateParam() |
||||||
* reinsetzen mit setFinalSelect() |
* Falls nach Aufruf der Prozedur ein select notwendig ist, |
||||||
* zum Schluss. getFinishedCall für fertigen Datenbankspezifischen |
* reinsetzen mit setFinalSelect() |
||||||
* Prozeduraufruf |
* zum Schluss. getFinishedCall für fertigen Datenbankspezifischen |
||||||
*/ |
* Prozeduraufruf |
||||||
public class ProcedureSql { |
*/ |
||||||
|
public class ProcedureSql { |
||||||
private DB dbsystem; |
|
||||||
private boolean isAddPossible = true,isNameSet, isFinished; |
private DB dbsystem; |
||||||
private String finalSelect = ""; |
|
||||||
|
private boolean isAddPossible = true, isNameSet, isFinished; |
||||||
private StringBuffer result = new StringBuffer(); |
|
||||||
|
private String finalSelect = ""; |
||||||
public ProcedureSql(DB db) { |
|
||||||
this.dbsystem = db; |
private StringBuffer result = new StringBuffer(); |
||||||
if (dbsystem.equals(DB.INFORMIX)) |
|
||||||
result.append("execute procedure "); |
public ProcedureSql(DB db) { |
||||||
if (dbsystem.equals(DB.POSTGRES)) |
this.dbsystem = db; |
||||||
result.append("select "); |
if (dbsystem.equals(DB.INFORMIX)) result.append("execute procedure "); |
||||||
|
if (dbsystem.equals(DB.POSTGRES)) result.append("select "); |
||||||
} |
|
||||||
|
} |
||||||
public ProcedureSql(DB dbsystem, String procname) { |
|
||||||
this(dbsystem); |
public ProcedureSql(DB dbsystem, String procname) { |
||||||
result.append(procname + ("(")); |
this(dbsystem); |
||||||
isNameSet=true; |
result.append(procname + ("(")); |
||||||
} |
isNameSet = true; |
||||||
public void setName(String procName) { |
} |
||||||
if (isNameSet)throw new IllegalStateException("Name wurde schon gesetzt"); |
|
||||||
result.append(procName+("(")); |
public void setName(String procName) { |
||||||
isNameSet=true; |
if (isNameSet) throw new IllegalStateException("Name wurde schon gesetzt"); |
||||||
} |
result.append(procName + ("(")); |
||||||
public void addParam(String param) { |
isNameSet = true; |
||||||
if (!isAddPossible) |
} |
||||||
throw new IllegalStateException("kann keine Parameter hinzufügen, vielleicht wurde getFinishedCall schon aufgerufen"); |
|
||||||
result.append(param + ","); |
public void addParam(String param) { |
||||||
} |
if (!isAddPossible) throw new IllegalStateException("kann keine Parameter hinzufügen, vielleicht wurde getFinishedCall schon aufgerufen"); |
||||||
public void addDateParam(String param) { |
result.append(param + ","); |
||||||
if (!isAddPossible) |
} |
||||||
throw new IllegalStateException("kann keine Parameter hinzufügen, vielleicht wurde getFinishedCall schon aufgerufen"); |
|
||||||
|
public void addDateParam(String param) { |
||||||
if (dbsystem.equals(DB.INFORMIX)) |
if (!isAddPossible) throw new IllegalStateException("kann keine Parameter hinzufügen, vielleicht wurde getFinishedCall schon aufgerufen"); |
||||||
result.append("date"); |
|
||||||
if (dbsystem.equals(DB.POSTGRES)) |
if (dbsystem.equals(DB.INFORMIX)) result.append("date"); |
||||||
result.append("date_val"); |
if (dbsystem.equals(DB.POSTGRES)) result.append("date_val"); |
||||||
result.append("('" + param + "'),"); |
result.append("('" + param + "'),"); |
||||||
} |
} |
||||||
public void setFinalSelect(String sel) { |
|
||||||
finalSelect = sel; |
public void setFinalSelect(String sel) { |
||||||
} |
finalSelect = sel; |
||||||
|
} |
||||||
public String getFinishedCall() { |
|
||||||
if (!isFinished) |
public String getFinishedCall() { |
||||||
finish(); |
if (!isFinished) finish(); |
||||||
return result.toString(); |
return result.toString(); |
||||||
} |
} |
||||||
|
|
||||||
private void finish() { |
private void finish() { |
||||||
addClosingBracket(); |
addClosingBracket(); |
||||||
result.append(finalSelect); |
result.append(finalSelect); |
||||||
isAddPossible = false; |
isAddPossible = false; |
||||||
isFinished = true; |
isFinished = true; |
||||||
} |
} |
||||||
|
|
||||||
private void addClosingBracket() { |
private void addClosingBracket() { |
||||||
char lc=result.charAt(result.length()-1);// StringUtils.getLastChar(result);
|
char lc = result.charAt(result.length() - 1);// StringUtils.getLastChar(result);
|
||||||
if (lc==',') |
if (lc == ',') StringUtils.deleteLastChar(result); |
||||||
StringUtils.deleteLastChar(result); |
result.append(");"); |
||||||
result.append(");"); |
} |
||||||
} |
|
||||||
|
public void addParam(Integer integer) { |
||||||
public void addParam(Integer integer) { |
addParam(integer.toString()); |
||||||
addParam(integer.toString()); |
} |
||||||
} |
|
||||||
|
public void addParam(int in) { |
||||||
public void addParam(int in) { |
addParam(Integer.valueOf(in).toString()); |
||||||
addParam(new Integer(in).toString()); |
} |
||||||
} |
|
||||||
|
public void addParam(Object param) { |
||||||
public void addParam(Object param) { |
addParam(param.toString()); |
||||||
addParam(param.toString()); |
} |
||||||
} |
|
||||||
|
public static void main(String args[]) { |
||||||
public static void main(String args[]) { |
ProcedureSql p = new ProcedureSql(DB.POSTGRES, "test"); |
||||||
ProcedureSql p=new ProcedureSql(DB.POSTGRES,"test"); |
p.addParam(23); |
||||||
p.addParam(23); |
System.out.println(p.getFinishedCall()); |
||||||
System.out.println(p.getFinishedCall()); |
} |
||||||
} |
} |
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
//Created on 03.12.2003 at 15:56:43
|
//Created on 03.12.2003 at 15:56:43
|
||||||
@ -1,72 +1,78 @@ |
|||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import de.memtext.baseobjects.NamedIdObject; |
import de.memtext.baseobjects.NamedIdObject; |
||||||
/** |
|
||||||
* Beschreibt eine (zusätzliche) in der Datenbank hinterlegt Eigenschaft. |
/** |
||||||
* (z.B. Accident meister) |
* Beschreibt eine (zusätzliche) in der Datenbank hinterlegt Eigenschaft. |
||||||
*/ |
* (z.B. Accident meister) |
||||||
public class PropDescriptor extends NamedIdObject { |
*/ |
||||||
//wie heißt die Spalte in der DB
|
public class PropDescriptor extends NamedIdObject { |
||||||
private String colname; |
//wie heißt die Spalte in der DB
|
||||||
//bei Combobox sql für quelle select key,name from xx
|
private String colname; |
||||||
private String quelle; |
|
||||||
//soll auf dem Bildschirm sichtbar sein
|
//bei Combobox sql für quelle select key,name from xx
|
||||||
private boolean isVisible; |
private String quelle; |
||||||
|
|
||||||
private String defaultkey; |
//soll auf dem Bildschirm sichtbar sein
|
||||||
private int sortnr; |
private boolean isVisible; |
||||||
|
|
||||||
|
private String defaultkey; |
||||||
public PropDescriptor() { |
|
||||||
|
private int sortnr; |
||||||
} |
|
||||||
|
|
||||||
public PropDescriptor(Object id, String name) { |
public PropDescriptor() { |
||||||
super(id,name); |
|
||||||
} |
} |
||||||
|
|
||||||
public String getColname() { |
public PropDescriptor(Object id, String name) { |
||||||
return colname; |
super(id, name); |
||||||
} |
} |
||||||
|
|
||||||
public void setColname(String colname) { |
public String getColname() { |
||||||
this.colname = colname; |
return colname; |
||||||
} |
} |
||||||
|
|
||||||
public String getDefaultkey() { |
public void setColname(String colname) { |
||||||
return defaultkey; |
this.colname = colname; |
||||||
} |
} |
||||||
|
|
||||||
public void setDefaultkey(String defaultkey) { |
public String getDefaultkey() { |
||||||
this.defaultkey = defaultkey; |
return defaultkey; |
||||||
} |
} |
||||||
|
|
||||||
public boolean isVisible() { |
public void setDefaultkey(String defaultkey) { |
||||||
return isVisible; |
this.defaultkey = defaultkey; |
||||||
} |
} |
||||||
|
|
||||||
public void setVisible(boolean isVisible) { |
public boolean isVisible() { |
||||||
this.isVisible = isVisible; |
return isVisible; |
||||||
} |
} |
||||||
|
|
||||||
public String getQuelle() { |
public void setVisible(boolean isVisible) { |
||||||
return quelle; |
this.isVisible = isVisible; |
||||||
} |
} |
||||||
|
|
||||||
public void setQuelle(String quelle) { |
public String getQuelle() { |
||||||
this.quelle = quelle; |
return quelle; |
||||||
} |
} |
||||||
|
|
||||||
public int getSortnr() { |
public void setQuelle(String quelle) { |
||||||
return sortnr; |
this.quelle = quelle; |
||||||
} |
} |
||||||
public void setSortnr(int sortnr) { |
|
||||||
this.sortnr = sortnr; |
public int getSortnr() { |
||||||
} |
return sortnr; |
||||||
public String toString() |
} |
||||||
{ |
|
||||||
return getName(); |
public void setSortnr(int sortnr) { |
||||||
} |
this.sortnr = sortnr; |
||||||
} |
} |
||||||
|
|
||||||
//Created on 17.05.2005 at 10:17:03
|
@Override |
||||||
|
public String toString() { |
||||||
|
return getName(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
//Created on 17.05.2005 at 10:17:03
|
||||||
|
|||||||
@ -1,88 +1,58 @@ |
|||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import java.io.File; |
import static de.superx.servlet.SxSQL_Server.DEFAULT_MANDANTEN_ID; |
||||||
import java.io.FileInputStream; |
|
||||||
import java.io.FileNotFoundException; |
import java.io.File; |
||||||
import java.io.IOException; |
import java.io.FileInputStream; |
||||||
import java.io.InputStream; |
import java.io.FileNotFoundException; |
||||||
import java.util.Properties; |
import java.io.IOException; |
||||||
import java.util.logging.Level; |
import java.io.InputStream; |
||||||
import java.util.logging.Logger; |
import java.util.Properties; |
||||||
|
|
||||||
import de.memtext.util.CryptUtils; |
import de.memtext.util.CryptUtils; |
||||||
|
|
||||||
public class PropsReader { |
public class PropsReader { |
||||||
private static byte key[] = { (byte) 255, (byte) 221, (byte) 127, |
private static byte key[] = { (byte) 255, (byte) 221, (byte) 127, (byte) 109, (byte) 129 }; |
||||||
(byte) 109, (byte) 129 }; |
|
||||||
private static int keyLength = key.length; |
/* |
||||||
/* |
* |
||||||
* |
* 28.10.08 EInfache Verschlüsselungsmethode wird nicht mehr unterstützt |
||||||
* 28.10.08 EInfache Verschlüsselungsmethode wird nicht mehr unterstützt |
*/ |
||||||
*/ |
public static String check(String mandantenID, String d) throws Exception { |
||||||
public static String check(String mandantenID, String d) throws Exception { |
String result = ""; |
||||||
String result = ""; |
if (d.startsWith("sx_des")) { |
||||||
// Logger.getLogger("superx_" + mandantenID).log(Level.FINEST,
|
result = CryptUtils.decryptStringDES(d.substring(6)); |
||||||
// "Verschlüsseltes Passwort " + d);
|
} else { |
||||||
if (d.startsWith("sx_des")) { |
result = d; |
||||||
result = CryptUtils.decryptStringDES(d.substring(6)); |
} |
||||||
} |
return result; |
||||||
else { |
} |
||||||
result=d; |
|
||||||
/* try { |
public static Properties prepareProps(File propfile) throws IOException, FileNotFoundException, Exception { |
||||||
byte[] tmp; |
Properties props = new Properties(); |
||||||
tmp = d.getBytes(); |
if (!propfile.exists()) { |
||||||
|
throw new IOException("Datei nicht gefunden: " + propfile); |
||||||
int size = (byte) (tmp[0] ^ key[0 % keyLength]); |
} |
||||||
int index = (byte) (tmp[1] ^ key[1 % keyLength]); |
InputStream is = new FileInputStream(propfile); |
||||||
byte de[] = new byte[size]; |
props.load(is); |
||||||
|
is.close(); |
||||||
for (int i = index; i < (size + index); i++) { |
String mandantenID = props.getProperty("MandantenID"); |
||||||
de[i - index] = (byte) (tmp[i] ^ key[i % keyLength]); |
if (mandantenID == null) mandantenID = DEFAULT_MANDANTEN_ID; |
||||||
} |
props.put("user", props.getProperty("connectionName")); |
||||||
result = new String(de); |
props.put("password", check(mandantenID, props.getProperty("connectionPassword"))); |
||||||
} catch (Exception e) { |
|
||||||
throw new DBServletException( |
if (props.getProperty("driverName").indexOf("postgres") > -1) { |
||||||
"Konnte Passwort nicht entschlüsseln (altes Verfahren). Bitte mit propadmin.x prüfen.\n" |
props.put("charSet", "Latin-1"); |
||||||
+ e); |
props.put("DateStyle", "German, DMY"); |
||||||
}*/ |
} |
||||||
} |
if (props.getProperty("driverName").indexOf("informix") > -1) |
||||||
return result; |
|
||||||
} |
{ |
||||||
|
props.put("GL_DATETIME", "%d.%m.%Y %T"); |
||||||
public static Properties prepareProps(File propfile) throws IOException, |
props.put("CLIENT_LOCALE", "de_de.8859-1"); |
||||||
FileNotFoundException, Exception { |
} |
||||||
Properties props = new Properties(); |
return props; |
||||||
if (!propfile.exists()) { |
} |
||||||
throw new IOException("Datei nicht gefunden: " + propfile); |
} |
||||||
} |
|
||||||
InputStream is = new FileInputStream(propfile); |
//Created on 27.04.2005 at 09:07:18
|
||||||
|
|
||||||
if (is != null) { |
|
||||||
props.load(is); |
|
||||||
is.close(); |
|
||||||
} else { |
|
||||||
throw new IOException("cannot open " + propfile); |
|
||||||
} |
|
||||||
String mandantenID = props.getProperty("MandantenID"); |
|
||||||
if (mandantenID == null) |
|
||||||
mandantenID = "default"; |
|
||||||
props.put("user", props.getProperty("connectionName")); |
|
||||||
props.put("password", check(mandantenID, props |
|
||||||
.getProperty("connectionPassword"))); |
|
||||||
|
|
||||||
if (props.getProperty("driverName").indexOf("postgres") > -1) { |
|
||||||
props.put("charSet", "Latin-1"); |
|
||||||
props.put("DateStyle", "German, DMY"); |
|
||||||
// props.put("DateStyle", "ISO, DMY");
|
|
||||||
} |
|
||||||
if (props.getProperty("driverName").indexOf("informix") > -1) |
|
||||||
|
|
||||||
{ |
|
||||||
props.put("GL_DATETIME", "%d.%m.%Y %T"); |
|
||||||
props.put("CLIENT_LOCALE", "de_de.8859-1"); |
|
||||||
} |
|
||||||
return props; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
//Created on 27.04.2005 at 09:07:18
|
|
||||||
|
|||||||
@ -1,90 +1,97 @@ |
|||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
/** |
|
||||||
* collects restrictions for sql-clauses, manages where and |
/** |
||||||
* and what to delete |
* collects restrictions for sql-clauses, manages where and |
||||||
* take care of inital where yourself |
* and what to delete |
||||||
*/ |
* take care of inital where yourself |
||||||
public class RestrictionCollector { |
*/ |
||||||
private StringBuffer restrict = new StringBuffer(); |
public class RestrictionCollector { |
||||||
|
private StringBuffer restrict = new StringBuffer(); |
||||||
private int count=0; |
|
||||||
public RestrictionCollector() { |
private int count = 0; |
||||||
} |
|
||||||
public RestrictionCollector(String restriction) { |
public RestrictionCollector() { |
||||||
restrict.append(restriction); |
} |
||||||
count = 1; |
|
||||||
|
public RestrictionCollector(String restriction) { |
||||||
} |
restrict.append(restriction); |
||||||
public boolean isSomethingAdded() |
count = 1; |
||||||
{ |
|
||||||
return count>0; |
} |
||||||
} |
|
||||||
public void addAndRestriction(StringBuffer restriction) { |
public boolean isSomethingAdded() { |
||||||
addAndRestriction(restriction.toString()); |
return count > 0; |
||||||
} |
} |
||||||
public void addAndRestriction(String restriction) { |
|
||||||
if (restriction==null||restriction.length()<3) |
public void addAndRestriction(StringBuffer restriction) { |
||||||
throw new IllegalArgumentException("Not OK:"+restriction); |
addAndRestriction(restriction.toString()); |
||||||
boolean isNewlineAtStart=restriction.startsWith("\n"); |
} |
||||||
restriction = restriction.trim(); |
|
||||||
if (isNewlineAtStart) restriction="\n"+restriction; |
public void addAndRestriction(String restriction) { |
||||||
if (restriction.substring(0, 3).equalsIgnoreCase("and")) |
if (restriction == null || restriction.length() < 3) throw new IllegalArgumentException("Not OK:" + restriction); |
||||||
restriction = restriction.substring(3); |
boolean isNewlineAtStart = restriction.startsWith("\n"); |
||||||
if (count>0) |
restriction = restriction.trim(); |
||||||
restrict.append(" and " + restriction + " "); |
if (isNewlineAtStart) restriction = "\n" + restriction; |
||||||
else |
if (restriction.substring(0, 3).equalsIgnoreCase("and")) restriction = restriction.substring(3); |
||||||
restrict.append(restriction + " "); |
if (count > 0) |
||||||
count++; |
restrict.append(" and " + restriction + " "); |
||||||
} |
else |
||||||
|
restrict.append(restriction + " "); |
||||||
public void addOrRestriction(StringBuffer restriction) { |
count++; |
||||||
addOrRestriction(restriction.toString()); |
} |
||||||
} |
|
||||||
public void addOrRestriction(String restriction) { |
public void addOrRestriction(StringBuffer restriction) { |
||||||
if (restriction==null||restriction.length()<3) |
addOrRestriction(restriction.toString()); |
||||||
throw new IllegalArgumentException("Not OK:"+restriction); |
} |
||||||
|
|
||||||
restriction = restriction.trim(); |
public void addOrRestriction(String restriction) { |
||||||
if (restriction.substring(0, 3).equalsIgnoreCase("or ")) |
if (restriction == null || restriction.length() < 3) throw new IllegalArgumentException("Not OK:" + restriction); |
||||||
restriction = restriction.substring(3); |
|
||||||
|
restriction = restriction.trim(); |
||||||
if (count>0) |
if (restriction.substring(0, 3).equalsIgnoreCase("or ")) restriction = restriction.substring(3); |
||||||
restrict.append(" or " + restriction + " "); |
|
||||||
else |
if (count > 0) |
||||||
restrict.append(restriction + " "); |
restrict.append(" or " + restriction + " "); |
||||||
count++; |
else |
||||||
} |
restrict.append(restriction + " "); |
||||||
public void addOrRestriction(RestrictionCollector collector) { |
count++; |
||||||
addOrRestriction(collector.toString()); |
} |
||||||
} |
|
||||||
public String toString() { |
public void addOrRestriction(RestrictionCollector collector) { |
||||||
if (count>0) |
addOrRestriction(collector.toString()); |
||||||
return restrict.toString(); |
} |
||||||
else |
|
||||||
return ""; |
@Override |
||||||
} |
public String toString() { |
||||||
public String toStringInclusiveWhere() |
if (count > 0) |
||||||
{ |
return restrict.toString(); |
||||||
if (count>0) |
else |
||||||
return " where "+restrict; |
return ""; |
||||||
else |
} |
||||||
return ""; |
|
||||||
} |
public String toStringInclusiveWhere() { |
||||||
public int getArgumentCount() |
if (count > 0) |
||||||
{ |
return " where " + restrict; |
||||||
return count; |
else |
||||||
} |
return ""; |
||||||
public void addAndRestriction(RestrictionCollector collector) { |
} |
||||||
if (collector.getArgumentCount()>1) |
|
||||||
addAndRestriction( collector.toString()); |
public int getArgumentCount() { |
||||||
else |
return count; |
||||||
addAndRestriction( collector.toString() ); |
} |
||||||
} |
|
||||||
public static void main(String[] args) { |
public void addAndRestriction(RestrictionCollector collector) { |
||||||
RestrictionCollector r = new RestrictionCollector(); |
if (collector.getArgumentCount() > 1) |
||||||
r.addAndRestriction(" AND 1=1"); |
addAndRestriction(collector.toString()); |
||||||
r.addAndRestriction("2=2"); |
else |
||||||
System.out.println(r); |
addAndRestriction(collector.toString()); |
||||||
} |
} |
||||||
} |
|
||||||
|
public static void main(String[] args) { |
||||||
|
RestrictionCollector r = new RestrictionCollector(); |
||||||
|
r.addAndRestriction(" AND 1=1"); |
||||||
|
r.addAndRestriction("2=2"); |
||||||
|
System.out.println(r); |
||||||
|
} |
||||||
|
} |
||||||
// Created on 23.07.2003
|
// Created on 23.07.2003
|
||||||
@ -1,124 +1,121 @@ |
|||||||
/* |
/* |
||||||
* Copyright (c) 2001-2004, The HSQL Development Group All rights reserved. |
* Copyright (c) 2001-2004, The HSQL Development Group All rights reserved. |
||||||
* |
* |
||||||
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
||||||
* modification, are permitted provided that the following conditions are met: |
* modification, are permitted provided that the following conditions are met: |
||||||
* |
* |
||||||
* Redistributions of source code must retain the above copyright notice, this |
* Redistributions of source code must retain the above copyright notice, this |
||||||
* list of conditions and the following disclaimer. |
* list of conditions and the following disclaimer. |
||||||
* |
* |
||||||
* Redistributions in binary form must reproduce the above copyright notice, |
* Redistributions in binary form must reproduce the above copyright notice, |
||||||
* this list of conditions and the following disclaimer in the documentation |
* this list of conditions and the following disclaimer in the documentation |
||||||
* and/or other materials provided with the distribution. |
* and/or other materials provided with the distribution. |
||||||
* |
* |
||||||
* Neither the name of the HSQL Development Group nor the names of its |
* Neither the name of the HSQL Development Group nor the names of its |
||||||
* contributors may be used to endorse or promote products derived from this |
* contributors may be used to endorse or promote products derived from this |
||||||
* software without specific prior written permission. |
* software without specific prior written permission. |
||||||
* |
* |
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG, OR |
* ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG, OR |
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
||||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
||||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
||||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
||||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||||
*/ |
*/ |
||||||
|
|
||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import java.awt.event.WindowAdapter; |
import java.awt.event.WindowAdapter; |
||||||
import java.awt.event.WindowEvent; |
import java.awt.event.WindowEvent; |
||||||
import java.io.IOException; |
import java.io.IOException; |
||||||
import java.sql.Connection; |
import java.sql.Connection; |
||||||
import java.sql.SQLException; |
import java.sql.SQLException; |
||||||
import java.sql.Statement; |
import java.sql.Statement; |
||||||
|
|
||||||
import javax.swing.JFrame; |
import javax.swing.JFrame; |
||||||
import javax.swing.JLabel; |
import javax.swing.JLabel; |
||||||
import javax.swing.JOptionPane; |
import javax.swing.JOptionPane; |
||||||
|
|
||||||
public class SampleApp extends JFrame { |
public class SampleApp extends JFrame { |
||||||
private Connection con = null; |
private Connection con = null; |
||||||
private String path = ""; // null , "" or "." for current directory
|
|
||||||
private String dbname = "testing"; |
private String path = ""; // null , "" or "." for current directory
|
||||||
|
|
||||||
public SampleApp() throws ClassNotFoundException, SQLException, IOException { |
private String dbname = "testing"; |
||||||
super("SampleApp"); |
|
||||||
initDb(); |
public SampleApp() throws ClassNotFoundException, SQLException, IOException { |
||||||
|
super("SampleApp"); |
||||||
JLabel lbl = new JLabel("got a connection to " |
initDb(); |
||||||
+ con.getMetaData().getURL()); |
|
||||||
this.getContentPane().add(lbl); |
JLabel lbl = new JLabel("got a connection to " + con.getMetaData().getURL()); |
||||||
this.setSize(600, 400); |
this.getContentPane().add(lbl); |
||||||
|
this.setSize(600, 400); |
||||||
addWindowListener(new WindowAdapter() { |
|
||||||
public void windowClosing(WindowEvent we) { |
addWindowListener(new WindowAdapter() { |
||||||
try { |
@Override |
||||||
String url=con.getMetaData().getURL(); |
public void windowClosing(WindowEvent we) { |
||||||
Statement stmt= con.createStatement(); |
try { |
||||||
stmt.execute("shutdown"); |
String url = con.getMetaData().getURL(); |
||||||
stmt.close(); |
Statement stmt = con.createStatement(); |
||||||
con.close(); |
stmt.execute("shutdown"); |
||||||
//delete all temporary files that may exists
|
stmt.close(); |
||||||
HsqlStandaloneMgr.deleteTmpFiles( url,path, dbname); |
con.close(); |
||||||
} catch (SQLException e) { |
//delete all temporary files that may exists
|
||||||
e.printStackTrace(); |
HsqlStandaloneMgr.deleteTmpFiles(url, path, dbname); |
||||||
} |
} catch (SQLException e) { |
||||||
System.exit(0); |
e.printStackTrace(); |
||||||
} |
} |
||||||
}); |
System.exit(0); |
||||||
|
} |
||||||
} |
}); |
||||||
|
|
||||||
private void initDb() throws ClassNotFoundException, SQLException, |
} |
||||||
IOException { |
|
||||||
|
private void initDb() throws ClassNotFoundException, SQLException, IOException { |
||||||
if (!HsqlStandaloneMgr.isDatabaseOpen(path, dbname)) { |
|
||||||
//if the database isn't open yet, we just open a regular connection
|
if (!HsqlStandaloneMgr.isDatabaseOpen(path, dbname)) { |
||||||
//the system username is written to a special properties file
|
//if the database isn't open yet, we just open a regular connection
|
||||||
con = HsqlStandaloneMgr.getConnection(path, dbname, "sa", ""); |
//the system username is written to a special properties file
|
||||||
Statement stmt = con.createStatement(); |
con = HsqlStandaloneMgr.getConnection(path, dbname, "sa", ""); |
||||||
stmt |
Statement stmt = con.createStatement(); |
||||||
.execute("drop table test if exists;create table test( col1 integer);insert into test values(1);checkpoint;"); |
stmt.execute("drop table test if exists;create table test( col1 integer);insert into test values(1);checkpoint;"); |
||||||
stmt.close(); |
stmt.close(); |
||||||
} else |
} else |
||||||
// the database is already open
|
// the database is already open
|
||||||
{ |
{ |
||||||
//you can decide if the temporary copy should be read-only mode
|
//you can decide if the temporary copy should be read-only mode
|
||||||
//if not, all changes to the database will be lost after closing
|
//if not, all changes to the database will be lost after closing
|
||||||
// the connection
|
// the connection
|
||||||
boolean isReadOnlyModeWanted = true; |
boolean isReadOnlyModeWanted = true; |
||||||
int result = HsqlStandaloneMgr.askUser(this, path, dbname, |
int result = HsqlStandaloneMgr.askUser(this, path, dbname, isReadOnlyModeWanted); |
||||||
isReadOnlyModeWanted); |
if (result == JOptionPane.YES_OPTION) { |
||||||
if (result == JOptionPane.YES_OPTION) { |
con = HsqlStandaloneMgr.getTmpConnection(this, path, dbname, "sa", "", isReadOnlyModeWanted); |
||||||
con = HsqlStandaloneMgr.getTmpConnection(this, path, dbname, |
} else { |
||||||
"sa", "", isReadOnlyModeWanted); |
// opening of temp. copy not wanted
|
||||||
} else |
System.exit(0); |
||||||
{ |
} |
||||||
// opening of temp. copy not wanted
|
} |
||||||
System.exit(0); |
} |
||||||
} |
|
||||||
} |
public static void main(String args[]) { |
||||||
} |
|
||||||
|
try { |
||||||
public static void main(String args[]) { |
SampleApp app = new SampleApp(); |
||||||
|
app.show(); |
||||||
try { |
} catch (ClassNotFoundException e) { |
||||||
SampleApp app = new SampleApp(); |
e.printStackTrace(); |
||||||
app.show(); |
} catch (SQLException e) { |
||||||
} catch (ClassNotFoundException e) { |
e.printStackTrace(); |
||||||
e.printStackTrace(); |
} catch (IOException e) { |
||||||
} catch (SQLException e) { |
e.printStackTrace(); |
||||||
e.printStackTrace(); |
} |
||||||
} catch (IOException e) { |
|
||||||
e.printStackTrace(); |
} |
||||||
} |
} |
||||||
|
|
||||||
} |
//Created on 23.10.2004 at 12:10:38
|
||||||
} |
|
||||||
|
|
||||||
//Created on 23.10.2004 at 12:10:38
|
|
||||||
|
|||||||
@ -1,48 +1,47 @@ |
|||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
|
|
||||||
import java.io.File; |
import java.io.File; |
||||||
import java.io.IOException; |
import java.io.IOException; |
||||||
import java.sql.Connection; |
import java.sql.Connection; |
||||||
import java.sql.DatabaseMetaData; |
import java.sql.DatabaseMetaData; |
||||||
import java.sql.ResultSet; |
import java.sql.ResultSet; |
||||||
import java.sql.SQLException; |
import java.sql.SQLException; |
||||||
|
|
||||||
import de.memtext.util.StringUtils; |
import org.apache.commons.io.FileUtils; |
||||||
|
|
||||||
public class SchemaReader { |
public class SchemaReader { |
||||||
|
|
||||||
public static void main(String[] args) { |
public static void main(String[] args) { |
||||||
if (args.length != 1) { |
if (args.length != 1) { |
||||||
System.out.println("SchemaReader db.properties"); |
System.out.println("SchemaReader db.properties"); |
||||||
System.exit(1); |
System.exit(1); |
||||||
} |
} |
||||||
try { |
try { |
||||||
Connection con = ConnectionCreator.getConnectionCryptPassword(args[0],"driverName","connectionURL","connectionName","connectionPassword"); |
Connection con = ConnectionCreator.getConnectionCryptPassword(args[0], "driverName", "connectionURL", "connectionName", "connectionPassword"); |
||||||
DatabaseMetaData md = con.getMetaData(); |
DatabaseMetaData md = con.getMetaData(); |
||||||
ResultSet myTables = md.getTables(null, null, null, null); |
ResultSet myTables = md.getTables(null, null, null, null); |
||||||
StringBuffer result = new StringBuffer(); |
StringBuffer result = new StringBuffer(); |
||||||
if (myTables != null) { |
if (myTables != null) { |
||||||
while (myTables.next()) { |
while (myTables.next()) { |
||||||
String tabname = myTables.getString(3); |
String tabname = myTables.getString(3); |
||||||
result.append("TABLE " + tabname + "\n"); |
result.append("TABLE " + tabname + "\n"); |
||||||
ResultSet cols = md.getColumns(null, null, tabname, null); |
ResultSet cols = md.getColumns(null, null, tabname, null); |
||||||
while (cols.next()) { |
while (cols.next()) { |
||||||
result.append(cols.getString(4) + ":" |
result.append(cols.getString(4) + ":" + cols.getObject(5) + "\n"); |
||||||
+ cols.getObject(5) + "\n"); |
} |
||||||
} |
result.append("----\n"); |
||||||
result.append("----\n"); |
} |
||||||
} |
} |
||||||
} |
FileUtils.writeStringToFile(new File("schema.txt"), result.toString()); |
||||||
StringUtils.write(new File("schema.txt"),result.toString()); |
|
||||||
|
} catch (IOException e) { |
||||||
} catch (IOException e) { |
e.printStackTrace(); |
||||||
e.printStackTrace(); |
} catch (SQLException e) { |
||||||
} catch (SQLException e) { |
e.printStackTrace(); |
||||||
e.printStackTrace(); |
} catch (ClassNotFoundException e) { |
||||||
} catch (ClassNotFoundException e) { |
e.printStackTrace(); |
||||||
e.printStackTrace(); |
} |
||||||
} |
} |
||||||
} |
} |
||||||
} |
|
||||||
|
//Created on 21.02.2006 at 10:38:08
|
||||||
//Created on 21.02.2006 at 10:38:08
|
|
||||||
|
|||||||
@ -1,266 +1,217 @@ |
|||||||
package de.memtext.db; |
package de.memtext.db; |
||||||
import java.io.BufferedWriter; |
|
||||||
import java.io.FileWriter; |
import java.io.BufferedWriter; |
||||||
import java.sql.Connection; |
import java.io.FileWriter; |
||||||
import java.sql.DriverManager; |
import java.sql.Connection; |
||||||
import java.sql.ResultSet; |
import java.sql.DriverManager; |
||||||
import java.sql.SQLException; |
import java.sql.ResultSet; |
||||||
import java.sql.Statement; |
import java.sql.SQLException; |
||||||
import java.util.Enumeration; |
import java.sql.Statement; |
||||||
import java.util.Random; |
import java.util.Enumeration; |
||||||
import java.util.Vector; |
import java.util.Random; |
||||||
/** |
import java.util.Vector; |
||||||
* Randomizes values in a database. |
|
||||||
* Reads all values of a given table column (select distinct x from..) and |
/** |
||||||
* multiplies all occurences of a single value (e.g. 150) with a factor between |
* Randomizes values in a database. |
||||||
* minFactor and maxFactor (e.g. 150*1.1 -> all entries with 150 become 165) |
* Reads all values of a given table column (select distinct x from..) and |
||||||
* |
* multiplies all occurences of a single value (e.g. 150) with a factor between |
||||||
* if boolean printOutOnly is true the update sql statements are only logged |
* minFactor and maxFactor (e.g. 150*1.1 -> all entries with 150 become 165) |
||||||
* to console, not performed |
* |
||||||
* */ |
* if boolean printOutOnly is true the update sql statements are only logged |
||||||
public class ValueRandomizer { |
* to console, not performed |
||||||
//private static String driver = "org.hsqldb.jdbcDriver";
|
* */ |
||||||
private static String driver = "org.postgresql.Driver"; |
public class ValueRandomizer { |
||||||
//private static String dbUrl = "jdbc:hsqldb:hsql://localhost:9999";
|
//private static String driver = "org.hsqldb.jdbcDriver";
|
||||||
private static String dbUrl = "jdbc:postgresql://localhost:5432/superx"; |
private static String driver = "org.postgresql.Driver"; |
||||||
private static String username = "superx"; //"joolap";
|
|
||||||
private static String password = ""; //"loopja3000";
|
//private static String dbUrl = "jdbc:hsqldb:hsql://localhost:9999";
|
||||||
private static String tablename = "cob_busa"; |
private static String dbUrl = "jdbc:postgresql://localhost:5432/superx"; |
||||||
private static String colname = "betrag"; //"value";
|
|
||||||
private static String datenart = "DOUBLE"; //or "INTEGER";
|
private static String username = "superx"; //"joolap";
|
||||||
|
|
||||||
private static double minFactor = 0.6; |
private static String password = ""; //"loopja3000";
|
||||||
private static double maxFactor = 1.8; |
|
||||||
|
private static String tablename = "cob_busa"; |
||||||
private static boolean printOutOnly = false; |
|
||||||
private static Statement stat; |
private static String colname = "betrag"; //"value";
|
||||||
private static Random r = new Random(); |
|
||||||
public static void main(String args[]) { |
private static String datenart = "DOUBLE"; //or "INTEGER";
|
||||||
|
|
||||||
try { |
private static double minFactor = 0.6; |
||||||
Class.forName(driver); |
|
||||||
Connection conn; |
private static double maxFactor = 1.8; |
||||||
System.out.println("establishing connection to " + dbUrl); |
|
||||||
conn = DriverManager.getConnection(dbUrl, username, password); |
private static boolean printOutOnly = false; |
||||||
stat = conn.createStatement(); |
|
||||||
System.out.println("done."); |
private static Statement stat; |
||||||
out(); |
|
||||||
stat.close(); |
private static Random r = new Random(); |
||||||
conn.close(); |
|
||||||
System.exit(-1); |
public static void main(String args[]) { |
||||||
|
|
||||||
|
try { |
||||||
//alle werte einlesen
|
Class.forName(driver); |
||||||
Vector werte = readDistinctValues(); |
Connection conn; |
||||||
if (datenart.toUpperCase().equalsIgnoreCase("DOUBLE")) { |
System.out.println("establishing connection to " + dbUrl); |
||||||
//massiveRandomizeDouble(werte);
|
conn = DriverManager.getConnection(dbUrl, username, password); |
||||||
randomize(werte); |
stat = conn.createStatement(); |
||||||
} else //integer
|
System.out.println("done."); |
||||||
{ |
out(); |
||||||
massiveRandomizeInteger(werte); |
stat.close(); |
||||||
} |
conn.close(); |
||||||
|
System.exit(-1); |
||||||
System.out.println("Randomizierung erfolgreich beendet"); |
|
||||||
} catch (Exception e) { |
|
||||||
System.out.println(e.toString()); |
//alle werte einlesen
|
||||||
System.exit(0); |
Vector werte = readDistinctValues(); |
||||||
} |
if (datenart.toUpperCase().equalsIgnoreCase("DOUBLE")) { |
||||||
|
//massiveRandomizeDouble(werte);
|
||||||
} |
randomize(werte); |
||||||
/** |
} else //integer
|
||||||
* randomizes in categories of values |
{ |
||||||
* only for double |
massiveRandomizeInteger(werte); |
||||||
* @param werte |
} |
||||||
*/ |
|
||||||
private static void randomize(Vector werte) { |
System.out.println("Randomizierung erfolgreich beendet"); |
||||||
int categories = 15; |
} catch (Exception e) { |
||||||
int valuesPerCategory = (int) werte.size() / categories; |
System.out.println(e.toString()); |
||||||
StringBuffer updates = new StringBuffer(); |
System.exit(0); |
||||||
float limit = 0, limit2; |
} |
||||||
for (int i = 1; i < categories; i++) { |
|
||||||
limit = |
} |
||||||
(float) ((Double) werte.get(i * valuesPerCategory)) |
|
||||||
.doubleValue(); |
/** |
||||||
updates.append( |
* randomizes in categories of values |
||||||
"update " |
* only for double |
||||||
+ tablename |
* @param werte |
||||||
+ " set " |
*/ |
||||||
+ colname |
private static void randomize(Vector werte) { |
||||||
+ "=" |
int categories = 15; |
||||||
+ colname |
int valuesPerCategory = (int) werte.size() / categories; |
||||||
+ "*" |
StringBuffer updates = new StringBuffer(); |
||||||
+ getRndFactor() |
float limit = 0, limit2; |
||||||
+ " where " |
for (int i = 1; i < categories; i++) { |
||||||
+ colname |
limit = (float) ((Double) werte.get(i * valuesPerCategory)).doubleValue(); |
||||||
+ ">" |
updates.append("update " + tablename + " set " + colname + "=" + colname + "*" + getRndFactor() + " where " + colname + ">" + limit); |
||||||
+ limit); |
if (i > 1) { |
||||||
if (i > 1) { |
limit2 = (float) ((Double) werte.get((i - 1) * valuesPerCategory)).doubleValue(); |
||||||
limit2 = |
updates.append(" and " + colname + "<" + limit2); |
||||||
(float) ((Double) werte.get((i - 1) * valuesPerCategory)) |
} |
||||||
.doubleValue(); |
updates.append(";\n"); |
||||||
updates.append(" and " + colname + "<" + limit2); |
} |
||||||
} |
limit = (float) ((Double) werte.get((categories - 1) * valuesPerCategory)).doubleValue(); |
||||||
updates.append(";\n"); |
updates.append("update " + tablename + " set " + colname + "=" + colname + "*" + getRndFactor() + " where " + colname + "<" + limit + ";"); |
||||||
} |
|
||||||
limit = |
System.out.println(updates); |
||||||
(float) ((Double) werte.get((categories - 1) * valuesPerCategory)) |
} |
||||||
.doubleValue(); |
|
||||||
updates.append( |
/** |
||||||
"update " |
* * multiplies all occurences of a single value (e.g. 150) with a factor between |
||||||
+ tablename |
* minFactor and maxFactor (e.g. 150*1.1 -> all entries with 150 become 165) |
||||||
+ " set " |
|
||||||
+ colname |
* @param werte |
||||||
+ "=" |
* @throws SQLException |
||||||
+ colname |
*/ |
||||||
+ "*" |
private static void massiveRandomizeInteger(Vector werte) throws SQLException { |
||||||
+ getRndFactor() |
Integer einWert; |
||||||
+ " where " |
String upd = null; |
||||||
+ colname |
for (Enumeration en = werte.elements(); en.hasMoreElements();) { |
||||||
+ "<" |
einWert = (Integer) en.nextElement(); |
||||||
+ limit |
int neuerwert = (int) (einWert.intValue() * getRndFactor()); |
||||||
+ ";"); |
upd = "update " + tablename + " set " + colname + "=" + neuerwert + " where " + colname + "=" + einWert.toString() + ";"; |
||||||
|
|
||||||
System.out.println(updates); |
if (printOutOnly) |
||||||
} |
System.out.println(upd); |
||||||
/** |
else |
||||||
* * multiplies all occurences of a single value (e.g. 150) with a factor between |
stat.executeUpdate(upd); |
||||||
* minFactor and maxFactor (e.g. 150*1.1 -> all entries with 150 become 165) |
} |
||||||
|
|
||||||
* @param werte |
} |
||||||
* @throws SQLException |
|
||||||
*/ |
/** |
||||||
private static void massiveRandomizeInteger(Vector werte) |
* * multiplies all occurences of a single value (e.g. 150) with a factor between |
||||||
throws SQLException { |
* minFactor and maxFactor (e.g. 150*1.1 -> all entries with 150 become 165) |
||||||
Integer einWert; |
|
||||||
String upd = null; |
* @param werte |
||||||
for (Enumeration en = werte.elements(); en.hasMoreElements();) { |
* @throws SQLException |
||||||
einWert = (Integer) en.nextElement(); |
*/ |
||||||
int neuerwert = (int) (einWert.intValue() * getRndFactor()); |
private static void massiveRandomizeDouble(Vector werte) throws SQLException { |
||||||
upd = |
Double einWert; |
||||||
"update " |
double zufallswert; |
||||||
+ tablename |
String upd; |
||||||
+ " set " |
int i = 0; |
||||||
+ colname |
int count = werte.size(); |
||||||
+ "=" |
for (Enumeration en = werte.elements(); en.hasMoreElements();) { |
||||||
+ neuerwert |
einWert = (Double) en.nextElement(); |
||||||
+ " where " |
i++; |
||||||
+ colname |
zufallswert = einWert.doubleValue() * getRndFactor(); |
||||||
+ "=" |
upd = "update " + tablename + " set " + colname + "=" + zufallswert + " where " + colname + "=" + einWert + ";"; |
||||||
+ einWert.toString() |
if (printOutOnly) |
||||||
+ ";"; |
System.out.println(upd); |
||||||
|
else { |
||||||
if (printOutOnly) |
stat.executeUpdate(upd); |
||||||
System.out.println(upd); |
if (i % 20 == 0) System.out.println("Done " + i + " updates of " + count); |
||||||
else |
} |
||||||
stat.executeUpdate(upd); |
|
||||||
} |
} |
||||||
|
} |
||||||
} |
|
||||||
/** |
private static float getRndFactor() { |
||||||
* * multiplies all occurences of a single value (e.g. 150) with a factor between |
double rnd = Math.abs(r.nextDouble()); |
||||||
* minFactor and maxFactor (e.g. 150*1.1 -> all entries with 150 become 165) |
while (rnd < minFactor) |
||||||
|
rnd += minFactor; |
||||||
* @param werte |
while (rnd > maxFactor) |
||||||
* @throws SQLException |
rnd -= 0.05; |
||||||
*/ |
return (float) rnd; |
||||||
private static void massiveRandomizeDouble(Vector werte) |
} |
||||||
throws SQLException { |
|
||||||
Double einWert; |
private static Vector readDistinctValues() throws SQLException { |
||||||
double zufallswert; |
Vector werte = new Vector(); |
||||||
String upd; |
ResultSet rs = null; |
||||||
int i = 0; |
Object item; |
||||||
int count = werte.size(); |
System.out.println("Alle werte einlesen:" + "select distinct " + colname + " from " + tablename + " order by 1 DESC"); |
||||||
for (Enumeration en = werte.elements(); en.hasMoreElements();) { |
|
||||||
einWert = (Double) en.nextElement(); |
rs = stat.executeQuery("select distinct " + colname + " from " + tablename + " order by " + colname + " DESC"); |
||||||
i++; |
while (rs.next()) { |
||||||
zufallswert = einWert.doubleValue() * getRndFactor(); |
item = rs.getObject(1); |
||||||
upd = |
werte.add(item); |
||||||
"update " |
} |
||||||
+ tablename |
rs.close(); |
||||||
+ " set " |
return werte; |
||||||
+ colname |
} |
||||||
+ "=" |
|
||||||
+ zufallswert |
private static void out() { |
||||||
+ " where " |
try { |
||||||
+ colname |
FileWriter fw = new FileWriter("c:\\cygwin\\home\\superx\\cob_busa.unl"); |
||||||
+ "=" |
BufferedWriter bw = new BufferedWriter(fw); |
||||||
+ einWert |
StringBuffer buf = new StringBuffer(); |
||||||
+ ";"; |
|
||||||
if (printOutOnly) |
ResultSet rs = stat.executeQuery("select * from cob_busa"); |
||||||
System.out.println(upd); |
|
||||||
else { |
int cols = 20; |
||||||
stat.executeUpdate(upd); |
String s; |
||||||
if (i % 20 == 0) |
Object o; |
||||||
System.out.println("Done " + i + " updates of " + count); |
while (rs.next()) { |
||||||
} |
for (int i = 1; i <= cols; i++) { |
||||||
|
o = rs.getObject(i); |
||||||
} |
if (o == null) |
||||||
} |
s = ""; |
||||||
private static float getRndFactor() { |
else |
||||||
double rnd = Math.abs(r.nextDouble()); |
s = o.toString(); |
||||||
while (rnd < minFactor) |
|
||||||
rnd += minFactor; |
buf.append(s.trim() + "^"); |
||||||
while (rnd > maxFactor) |
} |
||||||
rnd -= 0.05; |
buf.append("^\n"); |
||||||
return (float) rnd; |
|
||||||
} |
} |
||||||
private static Vector readDistinctValues() throws SQLException { |
rs.close(); |
||||||
Vector werte = new Vector(); |
|
||||||
ResultSet rs = null; |
bw.write(buf.toString()); |
||||||
Object item; |
bw.close(); |
||||||
System.out.println( |
fw.close(); |
||||||
"Alle werte einlesen:" |
} catch (Exception e) { |
||||||
+ "select distinct " |
e.printStackTrace(); |
||||||
+ colname |
} |
||||||
+ " from " |
System.out.println("done"); |
||||||
+ tablename |
} |
||||||
+ " order by 1 DESC"); |
} |
||||||
|
|
||||||
rs = |
|
||||||
stat.executeQuery( |
|
||||||
"select distinct " |
|
||||||
+ colname |
|
||||||
+ " from " |
|
||||||
+ tablename |
|
||||||
+ " order by " |
|
||||||
+ colname |
|
||||||
+ " DESC"); |
|
||||||
while (rs.next()) { |
|
||||||
item = rs.getObject(1); |
|
||||||
werte.add(item); |
|
||||||
} |
|
||||||
rs.close(); |
|
||||||
return werte; |
|
||||||
} |
|
||||||
|
|
||||||
private static void out() { |
|
||||||
try { |
|
||||||
FileWriter fw = |
|
||||||
new FileWriter("c:\\cygwin\\home\\superx\\cob_busa.unl"); |
|
||||||
BufferedWriter bw = new BufferedWriter(fw); |
|
||||||
StringBuffer buf = new StringBuffer(); |
|
||||||
|
|
||||||
ResultSet rs = stat.executeQuery("select * from cob_busa"); |
|
||||||
|
|
||||||
int cols = 20;String s;Object o; |
|
||||||
while (rs.next()) { |
|
||||||
for (int i = 1; i <= cols; i++) |
|
||||||
{o=rs.getObject(i); |
|
||||||
if (o==null) s=""; |
|
||||||
else s=o.toString(); |
|
||||||
|
|
||||||
buf.append(s.trim() + "^");} |
|
||||||
buf.append("^\n"); |
|
||||||
|
|
||||||
} |
|
||||||
rs.close(); |
|
||||||
|
|
||||||
bw.write(buf.toString()); |
|
||||||
bw.close(); |
|
||||||
fw.close(); |
|
||||||
} catch (Exception e) { |
|
||||||
e.printStackTrace(); |
|
||||||
} |
|
||||||
System.out.println("done"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|||||||
@ -1,69 +1,67 @@ |
|||||||
package de.memtext.db.dataexchange; |
package de.memtext.db.dataexchange; |
||||||
|
|
||||||
/** |
/** |
||||||
* Insert the type's description here. |
* Insert the type's description here. |
||||||
* Creation date: (29.11.2002 16:53:06) |
* Creation date: (29.11.2002 16:53:06) |
||||||
* @author: |
* @author: |
||||||
*/ |
*/ |
||||||
public class MyRequest implements java.io.Serializable { |
public class MyRequest implements java.io.Serializable { |
||||||
static final long serialVersionUID = -2L; |
static final long serialVersionUID = -2L; |
||||||
static final int NORMAL=1; |
|
||||||
static final int EXPECT_ONE_UPDATE=2; |
static final int NORMAL = 1; |
||||||
|
|
||||||
private String sql; |
static final int EXPECT_ONE_UPDATE = 2; |
||||||
private String name; |
|
||||||
private Object[] params; |
private String sql; |
||||||
private int type; |
|
||||||
public MyRequest(String name,String sql,Object[] params) |
private String name; |
||||||
{ |
|
||||||
this(name,sql,params,NORMAL); |
private Object[] params; |
||||||
} |
|
||||||
public MyRequest(String name,String sql,Object[] params,int type) |
private int type; |
||||||
{ |
|
||||||
setName(name); |
public MyRequest(String name, String sql, Object[] params) { |
||||||
setSql(sql); |
this(name, sql, params, NORMAL); |
||||||
setParams(params); |
} |
||||||
setType(type); |
|
||||||
} |
public MyRequest(String name, String sql, Object[] params, int type) { |
||||||
|
setName(name); |
||||||
public int getType() |
setSql(sql); |
||||||
{ |
setParams(params); |
||||||
return type; |
setType(type); |
||||||
} |
} |
||||||
|
|
||||||
public void setType(int type) |
public int getType() { |
||||||
{ |
return type; |
||||||
this.type=type; |
} |
||||||
} |
|
||||||
public String getName() |
public void setType(int type) { |
||||||
{ |
this.type = type; |
||||||
return name; |
} |
||||||
} |
|
||||||
|
public String getName() { |
||||||
public void setName(String name) |
return name; |
||||||
{ |
} |
||||||
this.name=name; |
|
||||||
} |
public void setName(String name) { |
||||||
|
this.name = name; |
||||||
public Object[] getParams() |
} |
||||||
{ |
|
||||||
return params; |
public Object[] getParams() { |
||||||
} |
return params; |
||||||
|
} |
||||||
public void setParams(Object[] params) |
|
||||||
{ |
public void setParams(Object[] params) { |
||||||
this.params=params; |
this.params = params; |
||||||
} |
} |
||||||
|
|
||||||
public String getSql() |
public String getSql() { |
||||||
{ |
return sql; |
||||||
return sql; |
} |
||||||
} |
|
||||||
|
public void setSql(String sql) { |
||||||
public void setSql(String sql) |
this.sql = sql; |
||||||
{ |
} |
||||||
this.sql=sql; |
|
||||||
} |
} |
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
|
|||||||
@ -1,49 +1,61 @@ |
|||||||
package de.memtext.db.dataexchange; |
package de.memtext.db.dataexchange; |
||||||
|
|
||||||
import java.util.Vector; |
import java.util.Vector; |
||||||
/** |
|
||||||
* Insert the type's description here. |
/** |
||||||
* Creation date: (28.11.2002 19:25:34) |
* Insert the type's description here. |
||||||
* @author: |
* Creation date: (28.11.2002 19:25:34) |
||||||
*/ |
* @author: |
||||||
public class MyServletResponse implements java.io.Serializable { |
*/ |
||||||
static final long serialVersionUID = -3L; |
public class MyServletResponse implements java.io.Serializable { |
||||||
private Vector result; |
static final long serialVersionUID = -3L; |
||||||
private boolean OK; |
|
||||||
private Exception exception; |
private Vector result; |
||||||
private int updatedRowsCount; |
|
||||||
|
private boolean OK; |
||||||
/** |
|
||||||
* MyServletResponse constructor comment. |
private Exception exception; |
||||||
*/ |
|
||||||
public MyServletResponse(Vector result, boolean OK, Exception exception) { |
private int updatedRowsCount; |
||||||
this.result = result; |
|
||||||
this.OK = OK; |
/** |
||||||
this.exception = exception; |
* MyServletResponse constructor comment. |
||||||
} |
*/ |
||||||
public Exception getException() { |
public MyServletResponse(Vector result, boolean OK, Exception exception) { |
||||||
return exception; |
this.result = result; |
||||||
} |
this.OK = OK; |
||||||
public Vector getResult() { |
this.exception = exception; |
||||||
return result; |
} |
||||||
} |
|
||||||
public boolean isOK() { |
public Exception getException() { |
||||||
return OK; |
return exception; |
||||||
} |
} |
||||||
public void setException(Exception exception) { |
|
||||||
this.exception = exception; |
public Vector getResult() { |
||||||
} |
return result; |
||||||
public void setOK(boolean OK) { |
} |
||||||
this.OK = OK; |
|
||||||
} |
public boolean isOK() { |
||||||
public void setResult(Vector result) { |
return OK; |
||||||
this.result = result; |
} |
||||||
} |
|
||||||
public int getUpdatedRowsCount() { |
public void setException(Exception exception) { |
||||||
return updatedRowsCount; |
this.exception = exception; |
||||||
} |
} |
||||||
|
|
||||||
public void setUpdatedRowsCount(int updatedRowsCount) { |
public void setOK(boolean OK) { |
||||||
this.updatedRowsCount = updatedRowsCount; |
this.OK = OK; |
||||||
} |
} |
||||||
|
|
||||||
|
public void setResult(Vector result) { |
||||||
|
this.result = result; |
||||||
|
} |
||||||
|
|
||||||
|
public int getUpdatedRowsCount() { |
||||||
|
return updatedRowsCount; |
||||||
|
} |
||||||
|
|
||||||
|
public void setUpdatedRowsCount(int updatedRowsCount) { |
||||||
|
this.updatedRowsCount = updatedRowsCount; |
||||||
|
} |
||||||
} |
} |
||||||
@ -1,49 +1,46 @@ |
|||||||
package de.memtext.dlg; |
package de.memtext.dlg; |
||||||
|
|
||||||
import java.awt.Dimension; |
import java.awt.Dimension; |
||||||
import java.awt.Frame; |
import java.awt.Frame; |
||||||
import java.awt.HeadlessException; |
import java.awt.HeadlessException; |
||||||
import java.io.IOException; |
import java.io.IOException; |
||||||
|
|
||||||
import javax.swing.JLabel; |
import javax.swing.JLabel; |
||||||
|
|
||||||
import de.memtext.util.BrowserLauncher; |
import de.memtext.util.BrowserLauncher; |
||||||
import de.memtext.util.WindowUtils; |
import de.memtext.util.WindowUtils; |
||||||
import de.memtext.widgets.VerticalBox; |
import de.memtext.widgets.VerticalBox; |
||||||
|
|
||||||
public class AboutDialog extends OkDlg { |
public class AboutDialog extends OkDlg { |
||||||
private JLabel infoLbl, homepageLabel; |
private JLabel infoLbl, homepageLabel; |
||||||
public AboutDialog( |
|
||||||
Frame parent, |
public AboutDialog(Frame parent, String title, String infoText, String homePageLink, final String homepageUrl) throws HeadlessException { |
||||||
String title, |
super(parent, title); |
||||||
String infoText, |
infoLbl = new JLabel(infoText); |
||||||
String homePageLink, |
homepageLabel = new JLabel("<html><u>" + homePageLink); |
||||||
final String homepageUrl) |
homepageLabel.addMouseListener(new java.awt.event.MouseAdapter() { |
||||||
throws HeadlessException { |
|
||||||
super(parent, title); |
@Override |
||||||
infoLbl = new JLabel(infoText); |
public void mouseClicked(java.awt.event.MouseEvent evt) { |
||||||
homepageLabel = new JLabel("<html><u>" + homePageLink); |
|
||||||
homepageLabel.addMouseListener(new java.awt.event.MouseAdapter() { |
try { |
||||||
public void mouseClicked(java.awt.event.MouseEvent evt) { |
BrowserLauncher.openURL(homepageUrl); |
||||||
|
} catch (IOException e) { |
||||||
try { |
e.printStackTrace(); |
||||||
BrowserLauncher.openURL(homepageUrl); |
} |
||||||
} catch (IOException e) { |
} |
||||||
e.printStackTrace(); |
}); |
||||||
} |
|
||||||
} |
VerticalBox vbox = new VerticalBox(); |
||||||
}); |
vbox.addWithCenterAlignment(infoLbl); |
||||||
|
vbox.addWithCenterAlignment(homepageLabel); |
||||||
VerticalBox vbox = new VerticalBox(); |
setCenter(vbox); |
||||||
vbox.addWithCenterAlignment(infoLbl); |
pack(); |
||||||
vbox.addWithCenterAlignment(homepageLabel); |
Dimension size = this.getSize(); |
||||||
setCenter(vbox); |
setSize(size.width + 30, size.height + 30); |
||||||
pack(); |
WindowUtils.center(this); |
||||||
Dimension size = this.getSize(); |
} |
||||||
setSize(size.width + 30, size.height + 30); |
|
||||||
WindowUtils.center(this); |
} |
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
//Created on 18.06.2004 at 12:20:35
|
//Created on 18.06.2004 at 12:20:35
|
||||||
@ -1,113 +1,106 @@ |
|||||||
package de.memtext.dlg; |
package de.memtext.dlg; |
||||||
|
|
||||||
import java.awt.BorderLayout; |
import java.awt.BorderLayout; |
||||||
import java.awt.Dialog; |
import java.awt.Dialog; |
||||||
import java.awt.Frame; |
import java.awt.Frame; |
||||||
import java.awt.GraphicsConfiguration; |
import java.awt.GraphicsConfiguration; |
||||||
import java.awt.HeadlessException; |
import java.awt.HeadlessException; |
||||||
import java.awt.event.WindowAdapter; |
import java.awt.event.WindowAdapter; |
||||||
import java.awt.event.WindowEvent; |
import java.awt.event.WindowEvent; |
||||||
|
|
||||||
import javax.swing.JComponent; |
import javax.swing.JComponent; |
||||||
import javax.swing.JDialog; |
import javax.swing.JDialog; |
||||||
|
|
||||||
public class DialogWithExit extends JDialog { |
public class DialogWithExit extends JDialog { |
||||||
|
|
||||||
public DialogWithExit() throws HeadlessException { |
public DialogWithExit() throws HeadlessException { |
||||||
super(); |
super(); |
||||||
initMe(); |
initMe(); |
||||||
} |
} |
||||||
|
|
||||||
public DialogWithExit(Frame owner) throws HeadlessException { |
public DialogWithExit(Frame owner) throws HeadlessException { |
||||||
super(owner); |
super(owner); |
||||||
initMe(); |
initMe(); |
||||||
} |
} |
||||||
|
|
||||||
public DialogWithExit(Frame owner, boolean arg1) throws HeadlessException { |
public DialogWithExit(Frame owner, boolean arg1) throws HeadlessException { |
||||||
super(owner, arg1); |
super(owner, arg1); |
||||||
initMe(); |
initMe(); |
||||||
} |
} |
||||||
|
|
||||||
public DialogWithExit(Frame owner, String arg1) throws HeadlessException { |
public DialogWithExit(Frame owner, String arg1) throws HeadlessException { |
||||||
super(owner, arg1); |
super(owner, arg1); |
||||||
initMe(); |
initMe(); |
||||||
} |
} |
||||||
|
|
||||||
public DialogWithExit(Frame owner, String arg1, boolean arg2) |
public DialogWithExit(Frame owner, String arg1, boolean arg2) throws HeadlessException { |
||||||
throws HeadlessException { |
super(owner, arg1, arg2); |
||||||
super(owner, arg1, arg2); |
initMe(); |
||||||
initMe(); |
} |
||||||
} |
|
||||||
|
public DialogWithExit(Frame owner, String arg1, boolean arg2, GraphicsConfiguration arg3) { |
||||||
public DialogWithExit( |
super(owner, arg1, arg2, arg3); |
||||||
Frame owner, |
initMe(); |
||||||
String arg1, |
} |
||||||
boolean arg2, |
|
||||||
GraphicsConfiguration arg3) { |
public DialogWithExit(Dialog owner) throws HeadlessException { |
||||||
super(owner, arg1, arg2, arg3); |
super(owner); |
||||||
initMe(); |
initMe(); |
||||||
} |
} |
||||||
|
|
||||||
public DialogWithExit(Dialog owner) throws HeadlessException { |
public DialogWithExit(Dialog owner, boolean arg1) throws HeadlessException { |
||||||
super(owner); |
super(owner, arg1); |
||||||
initMe(); |
initMe(); |
||||||
} |
} |
||||||
|
|
||||||
public DialogWithExit(Dialog owner, boolean arg1) throws HeadlessException { |
public DialogWithExit(Dialog owner, String arg1) throws HeadlessException { |
||||||
super(owner, arg1); |
super(owner, arg1); |
||||||
initMe(); |
initMe(); |
||||||
} |
} |
||||||
|
|
||||||
public DialogWithExit(Dialog owner, String arg1) throws HeadlessException { |
public DialogWithExit(Dialog owner, String arg1, boolean arg2) throws HeadlessException { |
||||||
super(owner, arg1); |
super(owner, arg1, arg2); |
||||||
initMe(); |
} |
||||||
} |
|
||||||
|
public DialogWithExit(Dialog owner, String arg1, boolean arg2, GraphicsConfiguration arg3) throws HeadlessException { |
||||||
public DialogWithExit(Dialog owner, String arg1, boolean arg2) |
super(owner, arg1, arg2, arg3); |
||||||
throws HeadlessException { |
initMe(); |
||||||
super(owner, arg1, arg2); |
} |
||||||
} |
|
||||||
|
private void initMe() { |
||||||
public DialogWithExit( |
addWindowListener(new WindowAdapter() { |
||||||
Dialog owner, |
@Override |
||||||
String arg1, |
public void windowClosing(WindowEvent we) { |
||||||
boolean arg2, |
exit(); |
||||||
GraphicsConfiguration arg3) |
} |
||||||
throws HeadlessException { |
}); |
||||||
super(owner, arg1, arg2, arg3); |
} |
||||||
initMe(); |
|
||||||
} |
/** |
||||||
private void initMe(){ |
* called if window is closed, does nothing by default, |
||||||
addWindowListener(new WindowAdapter() { |
* subclasses can override |
||||||
public void windowClosing(WindowEvent we) { |
* |
||||||
exit(); |
*/ |
||||||
} |
protected void exit() { |
||||||
}); |
} |
||||||
} |
|
||||||
/** |
//man könnte noch abfragen ob auch wirklich Borderlayout benutzt
|
||||||
* called if window is closed, does nothing by default, |
//wird
|
||||||
* subclasses can override |
/** |
||||||
* |
* installs a component in the center of the dialog |
||||||
*/ |
* @param comp |
||||||
protected void exit() { |
*/ |
||||||
} |
public void setCenter(JComponent comp) { |
||||||
|
this.getContentPane().add(comp, BorderLayout.CENTER); |
||||||
//man könnte noch abfragen ob auch wirklich Borderlayout benutzt
|
} |
||||||
//wird
|
|
||||||
/** |
/** |
||||||
* installs a component in the center of the dialog |
* installs a component in the notrh of the dialog |
||||||
* @param comp |
* @param comp |
||||||
*/ |
*/ |
||||||
public void setCenter(JComponent comp) { |
public void setNorth(JComponent comp) { |
||||||
this.getContentPane().add(comp, BorderLayout.CENTER); |
this.getContentPane().add(comp, BorderLayout.NORTH); |
||||||
} |
} |
||||||
/** |
} |
||||||
* installs a component in the notrh of the dialog |
|
||||||
* @param comp |
|
||||||
*/ |
|
||||||
public void setNorth(JComponent comp) { |
|
||||||
this.getContentPane().add(comp, BorderLayout.NORTH); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
//Created on 21.11.2003
|
//Created on 21.11.2003
|
||||||
@ -1,57 +1,57 @@ |
|||||||
package de.memtext.dlg; |
package de.memtext.dlg; |
||||||
|
|
||||||
import java.awt.Component; |
import java.awt.Component; |
||||||
import java.text.ParseException; |
import java.text.ParseException; |
||||||
|
|
||||||
import javax.swing.JOptionPane; |
import javax.swing.JOptionPane; |
||||||
|
|
||||||
import de.memtext.util.DateUtils; |
import de.memtext.util.DateUtils; |
||||||
import de.memtext.widgets.WarningMessage; |
import de.memtext.widgets.WarningMessage; |
||||||
|
|
||||||
public class EnterDateDlg { |
public class EnterDateDlg { |
||||||
private java.util.Date date; |
private java.util.Date date; |
||||||
private Component parentComp; |
|
||||||
private String title, text; |
private Component parentComp; |
||||||
|
|
||||||
public EnterDateDlg(Component parentComp, String text, String title) { |
private String title, text; |
||||||
this.parentComp = parentComp; |
|
||||||
this.title = title; |
public EnterDateDlg(Component parentComp, String text, String title) { |
||||||
this.text = text; |
this.parentComp = parentComp; |
||||||
} |
this.title = title; |
||||||
|
this.text = text; |
||||||
public boolean wasOkSelected() |
} |
||||||
{ |
|
||||||
return date!=null; |
public boolean wasOkSelected() { |
||||||
} |
return date != null; |
||||||
public void show() { |
} |
||||||
date = null; |
|
||||||
String in; |
public void show() { |
||||||
boolean ok = false; |
date = null; |
||||||
while (!ok) { |
String in; |
||||||
in = JOptionPane.showInputDialog(parentComp, text, title, |
boolean ok = false; |
||||||
JOptionPane.QUESTION_MESSAGE); |
while (!ok) { |
||||||
if (in == null) { |
in = JOptionPane.showInputDialog(parentComp, text, title, JOptionPane.QUESTION_MESSAGE); |
||||||
date = null; |
if (in == null) { |
||||||
ok = true; |
date = null; |
||||||
} else { |
ok = true; |
||||||
try { |
} else { |
||||||
date = DateUtils.parse(in); |
try { |
||||||
ok = true; |
date = DateUtils.parse(in); |
||||||
} catch (ParseException e) { |
ok = true; |
||||||
WarningMessage.show(parentComp, "Ungültige Datumseingabe", |
} catch (ParseException e) { |
||||||
title); |
WarningMessage.show(parentComp, "Ungültige Datumseingabe", title); |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
public static void main(String args[]) { |
public static void main(String args[]) { |
||||||
new EnterDateDlg(null, "test", "title").show(); |
new EnterDateDlg(null, "test", "title").show(); |
||||||
} |
} |
||||||
|
|
||||||
public java.util.Date getDate() { |
public java.util.Date getDate() { |
||||||
return date; |
return date; |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
//Created on 18.08.2004 at 12:36:12
|
//Created on 18.08.2004 at 12:36:12
|
||||||
|
|||||||
@ -1,63 +1,62 @@ |
|||||||
package de.memtext.dlg; |
package de.memtext.dlg; |
||||||
|
|
||||||
import java.awt.Frame; |
import java.awt.Frame; |
||||||
import java.io.File; |
import java.io.File; |
||||||
|
|
||||||
import javax.swing.JLabel; |
import javax.swing.JLabel; |
||||||
|
|
||||||
import de.memtext.util.FilenamesFilter; |
import de.memtext.util.FilenamesFilter; |
||||||
import de.memtext.util.WindowUtils; |
import de.memtext.util.WindowUtils; |
||||||
import de.memtext.widgets.FileSelectionPanel; |
import de.memtext.widgets.FileSelectionPanel; |
||||||
import de.memtext.widgets.VerticalBox; |
import de.memtext.widgets.VerticalBox; |
||||||
|
|
||||||
public class ImportDlg extends OkCancelDlg { |
public class ImportDlg extends OkCancelDlg { |
||||||
private JLabel lblTop = new JLabel(); |
private JLabel lblTop = new JLabel(); |
||||||
private FileSelectionPanel fsp = new FileSelectionPanel("Datei"); |
|
||||||
|
private FileSelectionPanel fsp = new FileSelectionPanel("Datei"); |
||||||
public ImportDlg(Frame owner, String title, String infoTxt) { |
|
||||||
super(owner, title, true); |
public ImportDlg(Frame owner, String title, String infoTxt) { |
||||||
VerticalBox vbox = new VerticalBox(); |
super(owner, title, true); |
||||||
lblTop.setText(infoTxt); |
VerticalBox vbox = new VerticalBox(); |
||||||
vbox.add(lblTop); |
lblTop.setText(infoTxt); |
||||||
vbox.add(fsp); |
vbox.add(lblTop); |
||||||
setCenter(vbox); |
vbox.add(fsp); |
||||||
this.pack(); |
setCenter(vbox); |
||||||
WindowUtils.center(this); |
this.pack(); |
||||||
|
WindowUtils.center(this); |
||||||
} |
|
||||||
|
} |
||||||
public void setCurrentDir(File defaultdir) |
|
||||||
{ |
public void setCurrentDir(File defaultdir) { |
||||||
fsp.setCurrentDir(defaultdir); |
fsp.setCurrentDir(defaultdir); |
||||||
} |
} |
||||||
/** |
|
||||||
|
/** |
||||||
* @param endings |
|
||||||
*/ |
* @param endings |
||||||
public void setFileFilter(String endings) { |
*/ |
||||||
fsp.setFileFilter(new FilenamesFilter("CSV oder XML Dateien", endings)); |
public void setFileFilter(String endings) { |
||||||
} |
fsp.setFileFilter(new FilenamesFilter("CSV oder XML Dateien", endings)); |
||||||
|
} |
||||||
protected void performOk() { |
|
||||||
this.dispose(); |
@Override |
||||||
} |
protected void performOk() { |
||||||
|
this.dispose(); |
||||||
protected void performCancel() { |
} |
||||||
this.dispose(); |
|
||||||
} |
@Override |
||||||
|
protected void performCancel() { |
||||||
public File getSelectedFile() { |
this.dispose(); |
||||||
return fsp.getSelectedFile(); |
} |
||||||
} |
|
||||||
|
public File getSelectedFile() { |
||||||
public static void main(String[] args) { |
return fsp.getSelectedFile(); |
||||||
ImportDlg d = |
} |
||||||
new ImportDlg( |
|
||||||
null, |
public static void main(String[] args) { |
||||||
"titl", |
ImportDlg d = new ImportDlg(null, "titl", "Unfälle importieren aus CSV- oder XML-Datei (z.B. Universum Unfallanzeige 3.0)"); |
||||||
"Unfälle importieren aus CSV- oder XML-Datei (z.B. Universum Unfallanzeige 3.0)"); |
d.setFileFilter(".xml|.csv"); |
||||||
d.setFileFilter(".xml|.csv"); |
d.show(); |
||||||
d.show(); |
} |
||||||
} |
} |
||||||
} |
|
||||||
//Created on 19.02.2004 at 11:56:06
|
//Created on 19.02.2004 at 11:56:06
|
||||||
@ -1,40 +1,34 @@ |
|||||||
package de.memtext.dlg; |
package de.memtext.dlg; |
||||||
|
|
||||||
import java.util.ArrayList; |
import java.util.ArrayList; |
||||||
import java.util.Collection; |
import java.util.Collection; |
||||||
import java.util.Iterator; |
import java.util.Iterator; |
||||||
|
|
||||||
import javax.swing.JOptionPane; |
import javax.swing.JOptionPane; |
||||||
|
|
||||||
/** |
/** |
||||||
Convienience class to create and Input Dialog with JOptionPane. |
Convienience class to create and Input Dialog with JOptionPane. |
||||||
I.e. selection item from drop down (combobox) |
I.e. selection item from drop down (combobox) |
||||||
*/ |
*/ |
||||||
public class InputDialog { |
public class InputDialog { |
||||||
private String title, txt; |
private String title, txt; |
||||||
private ArrayList list; |
|
||||||
|
private ArrayList list; |
||||||
public InputDialog(Collection col, String title, String txt) { |
|
||||||
super(); |
public InputDialog(Collection col, String title, String txt) { |
||||||
this.title = title; |
super(); |
||||||
this.txt = txt; |
this.title = title; |
||||||
list = new ArrayList(); |
this.txt = txt; |
||||||
if (col==null||col.size()==0) throw new IllegalArgumentException("Collection mustn't be null or empty"); |
list = new ArrayList(); |
||||||
for (Iterator it = col.iterator(); it.hasNext();) { |
if (col == null || col.size() == 0) throw new IllegalArgumentException("Collection mustn't be null or empty"); |
||||||
list.add(it.next()); |
for (Iterator it = col.iterator(); it.hasNext();) { |
||||||
} |
list.add(it.next()); |
||||||
} |
} |
||||||
|
} |
||||||
public Object show() { |
|
||||||
return JOptionPane.showInputDialog( |
public Object show() { |
||||||
null, |
return JOptionPane.showInputDialog(null, txt, title, JOptionPane.QUESTION_MESSAGE, null, list.toArray(), null); |
||||||
txt, |
} |
||||||
title, |
} |
||||||
JOptionPane.QUESTION_MESSAGE, |
|
||||||
null, |
|
||||||
list.toArray(), |
|
||||||
null); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,67 +1,74 @@ |
|||||||
package de.memtext.dlg; |
package de.memtext.dlg; |
||||||
|
|
||||||
import javax.swing.JFrame; |
import javax.swing.JFrame; |
||||||
|
|
||||||
import de.memtext.widgets.LabeledPasswordField; |
import de.memtext.widgets.LabeledPasswordField; |
||||||
import de.memtext.widgets.LabeledTextField; |
import de.memtext.widgets.LabeledTextField; |
||||||
import de.memtext.widgets.MultilineEditPanel; |
import de.memtext.widgets.MultilineEditPanel; |
||||||
|
|
||||||
/** |
/** |
||||||
A Login Dialog |
A Login Dialog |
||||||
*/ |
*/ |
||||||
public class LoginDlg extends OkCancelDlg { |
public class LoginDlg extends OkCancelDlg { |
||||||
private LabeledTextField lUser = new LabeledTextField("Kennung", 15); |
private LabeledTextField lUser = new LabeledTextField("Kennung", 15); |
||||||
private LabeledPasswordField lPass = |
|
||||||
new LabeledPasswordField("Passwort", 15); |
private LabeledPasswordField lPass = new LabeledPasswordField("Passwort", 15); |
||||||
public LoginDlg(JFrame frame, String title) { |
|
||||||
super(frame, title,true); |
public LoginDlg(JFrame frame, String title) { |
||||||
initdlg(); |
super(frame, title, true); |
||||||
} |
initdlg(); |
||||||
|
} |
||||||
private void initdlg() { |
|
||||||
MultilineEditPanel vbox = new MultilineEditPanel(); |
private void initdlg() { |
||||||
vbox.add(lUser); |
MultilineEditPanel vbox = new MultilineEditPanel(); |
||||||
vbox.add(lPass); |
vbox.add(lUser); |
||||||
this.setCenter(vbox); |
vbox.add(lPass); |
||||||
this.pack(); |
this.setCenter(vbox); |
||||||
} |
this.pack(); |
||||||
|
} |
||||||
protected void performOk() { |
|
||||||
this.hide(); |
@Override |
||||||
} |
protected void performOk() { |
||||||
public void setUsername(String username) |
this.hide(); |
||||||
{ |
} |
||||||
lUser.setValue(username); |
|
||||||
} |
public void setUsername(String username) { |
||||||
public void setPassword(String password) |
lUser.setValue(username); |
||||||
{ |
} |
||||||
lPass.setValue(password); |
|
||||||
} |
public void setPassword(String password) { |
||||||
protected void performCancel() { |
lPass.setValue(password); |
||||||
this.hide(); |
} |
||||||
} |
|
||||||
public String getUsername() { |
@Override |
||||||
return lUser.getValue().toString(); |
protected void performCancel() { |
||||||
} |
this.hide(); |
||||||
/** |
} |
||||||
* can be returned only once, cleared for security reasons |
|
||||||
* afterwards |
public String getUsername() { |
||||||
* @return |
return lUser.getValue().toString(); |
||||||
*/ |
} |
||||||
public String getPassword() { |
|
||||||
/* char[] pw = passw.getPassword(); |
/** |
||||||
String result = new String(pw); |
* can be returned only once, cleared for security reasons |
||||||
for (int i = 0; i < pw.length; i++) { |
* afterwards |
||||||
pw[i] = 0; |
* @return |
||||||
} |
*/ |
||||||
return result; |
public String getPassword() { |
||||||
*/ |
/* char[] pw = passw.getPassword(); |
||||||
return lPass.getValue().toString(); |
String result = new String(pw); |
||||||
} |
for (int i = 0; i < pw.length; i++) { |
||||||
public static void main(String args[]) { |
pw[i] = 0; |
||||||
LoginDlg d=new LoginDlg(null,"asdf"); |
} |
||||||
d.show(); |
return result; |
||||||
System.out.println(d.getPassword()); |
*/ |
||||||
|
return lPass.getValue().toString(); |
||||||
} |
} |
||||||
} |
|
||||||
|
public static void main(String args[]) { |
||||||
|
LoginDlg d = new LoginDlg(null, "asdf"); |
||||||
|
d.show(); |
||||||
|
System.out.println(d.getPassword()); |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|||||||
@ -1,113 +1,132 @@ |
|||||||
package de.memtext.dlg; |
package de.memtext.dlg; |
||||||
|
|
||||||
import java.awt.Dimension; |
import java.awt.Dimension; |
||||||
import java.awt.Frame; |
import java.awt.Frame; |
||||||
import java.awt.event.WindowAdapter; |
import java.awt.event.WindowAdapter; |
||||||
import java.awt.event.WindowEvent; |
import java.awt.event.WindowEvent; |
||||||
|
|
||||||
import javax.swing.JScrollPane; |
import javax.swing.JScrollPane; |
||||||
import javax.swing.JTree; |
import javax.swing.JTree; |
||||||
import javax.swing.tree.DefaultTreeModel; |
import javax.swing.tree.DefaultTreeModel; |
||||||
import javax.swing.tree.TreeCellRenderer; |
import javax.swing.tree.TreeCellRenderer; |
||||||
import javax.swing.tree.TreeNode; |
import javax.swing.tree.TreeNode; |
||||||
|
|
||||||
import de.memtext.util.WindowUtils; |
import de.memtext.util.WindowUtils; |
||||||
|
|
||||||
/** |
/** |
||||||
* A dialog that presents a tree and allows the selection of |
* A dialog that presents a tree and allows the selection of |
||||||
* one node or to clear the selection |
* one node or to clear the selection |
||||||
*/ |
*/ |
||||||
public class NodeSelectionDlg extends OkCancelClearDlg { |
public class NodeSelectionDlg extends OkCancelClearDlg { |
||||||
private JTree tree; |
private JTree tree; |
||||||
private Object selectedNode = null; |
|
||||||
private String title; |
private Object selectedNode = null; |
||||||
public NodeSelectionDlg(Frame owner, String title, JTree tree) { |
|
||||||
super(owner, title); |
private String title; |
||||||
this.tree = tree; |
|
||||||
this.title=title; |
public NodeSelectionDlg(Frame owner, String title, JTree tree) { |
||||||
this.setCenter(new JScrollPane(tree)); |
super(owner, title); |
||||||
selectedNode = null; |
this.tree = tree; |
||||||
if (tree.getLastSelectedPathComponent() != null) |
this.title = title; |
||||||
selectedNode = (TreeNode) tree.getLastSelectedPathComponent(); |
this.setCenter(new JScrollPane(tree)); |
||||||
this.pack(); |
selectedNode = null; |
||||||
WindowUtils.center(this); |
if (tree.getLastSelectedPathComponent() != null) selectedNode = (TreeNode) tree.getLastSelectedPathComponent(); |
||||||
addWindowListener(new WindowAdapter() { |
this.pack(); |
||||||
public void windowClosing(WindowEvent we) { |
WindowUtils.center(this); |
||||||
exit(); |
addWindowListener(new WindowAdapter() { |
||||||
} |
@Override |
||||||
}); |
public void windowClosing(WindowEvent we) { |
||||||
} |
exit(); |
||||||
/** |
} |
||||||
* called if window is closed, does nothing by default, |
}); |
||||||
* subclasses can override |
} |
||||||
* |
|
||||||
*/ |
/** |
||||||
protected void exit() { |
* called if window is closed, does nothing by default, |
||||||
} |
* subclasses can override |
||||||
|
* |
||||||
public NodeSelectionDlg( |
*/ |
||||||
Frame owner, |
@Override |
||||||
String title, |
protected void exit() { |
||||||
DefaultTreeModel treeModel) { |
} |
||||||
this(owner, title, new JTree(treeModel)); |
|
||||||
} |
public NodeSelectionDlg(Frame owner, String title, DefaultTreeModel treeModel) { |
||||||
public NodeSelectionDlg(Frame owner, String title, TreeNode node) { |
this(owner, title, new JTree(treeModel)); |
||||||
this(owner, title, new JTree(node)); |
} |
||||||
} |
|
||||||
/** |
public NodeSelectionDlg(Frame owner, String title, TreeNode node) { |
||||||
* can be overriden by subclasses to perform a check if |
this(owner, title, new JTree(node)); |
||||||
* the selected node is OK |
} |
||||||
* @return |
|
||||||
*/ |
/** |
||||||
protected boolean isSelectedNodeOk(TreeNode testme) |
* can be overriden by subclasses to perform a check if |
||||||
{ |
* the selected node is OK |
||||||
return true; |
* @return |
||||||
} |
*/ |
||||||
protected void performOk() { |
protected boolean isSelectedNodeOk(TreeNode testme) { |
||||||
if (!isSelectedNodeOk((TreeNode)tree.getLastSelectedPathComponent())) return; |
return true; |
||||||
selectedNode = tree.getLastSelectedPathComponent(); |
} |
||||||
this.setVisible(false); |
|
||||||
} |
@Override |
||||||
|
protected void performOk() { |
||||||
protected void performCancel() { |
if (!isSelectedNodeOk((TreeNode) tree.getLastSelectedPathComponent())) return; |
||||||
this.setVisible(false); |
selectedNode = tree.getLastSelectedPathComponent(); |
||||||
} |
this.setVisible(false); |
||||||
public TreeNode getSelectedNode() { |
} |
||||||
return selectedNode == null ? null : (TreeNode) selectedNode; |
|
||||||
} |
@Override |
||||||
protected void performClear() { |
protected void performCancel() { |
||||||
selectedNode = null; |
this.setVisible(false); |
||||||
tree.clearSelection(); |
} |
||||||
this.setVisible(false); |
|
||||||
} |
public TreeNode getSelectedNode() { |
||||||
public void setSize(Dimension dim) { |
return selectedNode == null ? null : (TreeNode) selectedNode; |
||||||
super.setSize(dim); |
} |
||||||
WindowUtils.center(this); |
|
||||||
} |
@Override |
||||||
public void setSize(int x, int y) { |
protected void performClear() { |
||||||
super.setSize(x, y); |
selectedNode = null; |
||||||
WindowUtils.center(this); |
tree.clearSelection(); |
||||||
} |
this.setVisible(false); |
||||||
public static void main(String a[]) { |
} |
||||||
NodeSelectionDlg t = new NodeSelectionDlg(null, "adsf", new JTree()); |
|
||||||
t.pack(); |
@Override |
||||||
t.show(); |
public void setSize(Dimension dim) { |
||||||
System.out.println(t.getSelectedNode()); |
super.setSize(dim); |
||||||
t.show(); |
WindowUtils.center(this); |
||||||
System.out.println(t.getSelectedNode()); |
} |
||||||
} |
|
||||||
public void setNode(TreeNode node) { |
@Override |
||||||
tree.setModel(new DefaultTreeModel(node)); |
public void setSize(int x, int y) { |
||||||
selectedNode=null; |
super.setSize(x, y); |
||||||
} |
WindowUtils.center(this); |
||||||
public void setCellRenderer(TreeCellRenderer renderer) { |
} |
||||||
tree.setCellRenderer(renderer); |
|
||||||
} |
public static void main(String a[]) { |
||||||
public String getTitle() { |
NodeSelectionDlg t = new NodeSelectionDlg(null, "adsf", new JTree()); |
||||||
return title; |
t.pack(); |
||||||
} |
t.show(); |
||||||
public String getInfoText() { |
System.out.println(t.getSelectedNode()); |
||||||
return title; |
t.show(); |
||||||
} |
System.out.println(t.getSelectedNode()); |
||||||
} |
} |
||||||
|
|
||||||
|
public void setNode(TreeNode node) { |
||||||
|
tree.setModel(new DefaultTreeModel(node)); |
||||||
|
selectedNode = null; |
||||||
|
} |
||||||
|
|
||||||
|
public void setCellRenderer(TreeCellRenderer renderer) { |
||||||
|
tree.setCellRenderer(renderer); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String getTitle() { |
||||||
|
return title; |
||||||
|
} |
||||||
|
|
||||||
|
public String getInfoText() { |
||||||
|
return title; |
||||||
|
} |
||||||
|
} |
||||||
//Created on 17.11.2003
|
//Created on 17.11.2003
|
||||||
@ -1,54 +1,56 @@ |
|||||||
package de.memtext.dlg; |
package de.memtext.dlg; |
||||||
|
|
||||||
import java.awt.Frame; |
import java.awt.Frame; |
||||||
import java.awt.HeadlessException; |
import java.awt.HeadlessException; |
||||||
import java.util.Iterator; |
import java.util.Iterator; |
||||||
import java.util.LinkedList; |
import java.util.LinkedList; |
||||||
import java.util.List; |
import java.util.List; |
||||||
|
|
||||||
import javax.swing.JScrollPane; |
import javax.swing.JScrollPane; |
||||||
|
|
||||||
import de.memtext.widgets.ObjectCheckBox; |
import de.memtext.util.WindowUtils; |
||||||
import de.memtext.widgets.VerticalBox; |
import de.memtext.widgets.ObjectCheckBox; |
||||||
import de.memtext.util.WindowUtils; |
import de.memtext.widgets.VerticalBox; |
||||||
|
|
||||||
public class ObjectCheckBoxDlg extends OkCancelDlg { |
public class ObjectCheckBoxDlg extends OkCancelDlg { |
||||||
private List boxList = new LinkedList(); |
private List boxList = new LinkedList(); |
||||||
private List selectedObjectsList; |
|
||||||
public ObjectCheckBoxDlg(Frame frame, String title, List itemList,boolean selected) |
private List selectedObjectsList; |
||||||
throws HeadlessException { |
|
||||||
super(frame, title); |
public ObjectCheckBoxDlg(Frame frame, String title, List itemList, boolean selected) throws HeadlessException { |
||||||
VerticalBox vbox = new VerticalBox(); |
super(frame, title); |
||||||
for (Iterator it = itemList.iterator(); it.hasNext();) { |
VerticalBox vbox = new VerticalBox(); |
||||||
Object element = (Object) it.next(); |
for (Iterator it = itemList.iterator(); it.hasNext();) { |
||||||
ObjectCheckBox cb = new ObjectCheckBox(element,selected); |
Object element = (Object) it.next(); |
||||||
boxList.add(cb); |
ObjectCheckBox cb = new ObjectCheckBox(element, selected); |
||||||
vbox.add(cb); |
boxList.add(cb); |
||||||
} |
vbox.add(cb); |
||||||
this.setCenter(new JScrollPane(vbox)); |
} |
||||||
this.pack(); |
this.setCenter(new JScrollPane(vbox)); |
||||||
WindowUtils.center(this); |
this.pack(); |
||||||
} |
WindowUtils.center(this); |
||||||
|
} |
||||||
protected void performOk() { |
|
||||||
selectedObjectsList=new LinkedList(); |
@Override |
||||||
for (Iterator it = boxList.iterator(); it.hasNext();) { |
protected void performOk() { |
||||||
ObjectCheckBox element = (ObjectCheckBox) it.next(); |
selectedObjectsList = new LinkedList(); |
||||||
if (element.isSelected()) |
for (Iterator it = boxList.iterator(); it.hasNext();) { |
||||||
selectedObjectsList.add(element.getObject()); |
ObjectCheckBox element = (ObjectCheckBox) it.next(); |
||||||
} |
if (element.isSelected()) selectedObjectsList.add(element.getObject()); |
||||||
this.hide(); |
} |
||||||
} |
this.hide(); |
||||||
|
} |
||||||
protected void performCancel() { |
|
||||||
selectedObjectsList=new LinkedList(); |
@Override |
||||||
this.hide(); |
protected void performCancel() { |
||||||
} |
selectedObjectsList = new LinkedList(); |
||||||
|
this.hide(); |
||||||
public List getSelectedObjectsList() { |
} |
||||||
return selectedObjectsList; |
|
||||||
} |
public List getSelectedObjectsList() { |
||||||
|
return selectedObjectsList; |
||||||
} |
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
//Created on 26.11.2003 at 12:47:31
|
//Created on 26.11.2003 at 12:47:31
|
||||||
@ -1,72 +1,80 @@ |
|||||||
package de.memtext.dlg; |
package de.memtext.dlg; |
||||||
|
|
||||||
import java.awt.Frame; |
import java.awt.Frame; |
||||||
import java.awt.HeadlessException; |
import java.awt.HeadlessException; |
||||||
import java.awt.event.ActionEvent; |
import java.awt.event.ActionEvent; |
||||||
import java.awt.event.ActionListener; |
import java.awt.event.ActionListener; |
||||||
|
|
||||||
import javax.swing.JButton; |
import javax.swing.JButton; |
||||||
import javax.swing.JFrame; |
import javax.swing.JFrame; |
||||||
import javax.swing.JLabel; |
import javax.swing.JLabel; |
||||||
|
|
||||||
/** |
/** |
||||||
* Abstract Dialog in which OK or Cancel can be clicked. |
* Abstract Dialog in which OK or Cancel can be clicked. |
||||||
* Subclasses must implement performCancel and performOk. |
* Subclasses must implement performCancel and performOk. |
||||||
* setCenter for convenience. |
* setCenter for convenience. |
||||||
* |
* |
||||||
It's important that clients don't call |
It's important that clients don't call |
||||||
getContentPane().setLayout(new BorderLayout()) or something like that, |
getContentPane().setLayout(new BorderLayout()) or something like that, |
||||||
because that will cause southPanel to disappear |
because that will cause southPanel to disappear |
||||||
*/ |
*/ |
||||||
public abstract class OkCancelClearDlg |
public abstract class OkCancelClearDlg extends OkCancelDlg { |
||||||
extends OkCancelDlg |
private boolean wasClearSelected; |
||||||
{ |
|
||||||
private boolean wasClearSelected; |
protected JButton btnClear = new JButton("Leeren"); |
||||||
protected JButton btnClear = new JButton("Leeren"); |
|
||||||
/** |
/** |
||||||
* Constructor for OkCancelClearDlg. |
* Constructor for OkCancelClearDlg. |
||||||
* @param arg0 |
* @param arg0 |
||||||
* @param arg1 |
* @param arg1 |
||||||
* @throws HeadlessException |
* @throws HeadlessException |
||||||
*/ |
*/ |
||||||
public OkCancelClearDlg(Frame arg0, String title) |
public OkCancelClearDlg(Frame arg0, String title) throws HeadlessException { |
||||||
throws HeadlessException { |
super(arg0, title, true); |
||||||
super(arg0, title, true); |
initOkCancelClearDlg(); |
||||||
initOkCancelClearDlg(); |
} |
||||||
} |
|
||||||
|
private void initOkCancelClearDlg() { |
||||||
private void initOkCancelClearDlg() { |
|
||||||
|
btnClear.setActionCommand("Clear"); |
||||||
btnClear.setActionCommand("Clear"); |
btnClear.addActionListener(new ActionListener() { |
||||||
btnClear.addActionListener(new ActionListener() { |
|
||||||
public void actionPerformed(ActionEvent ae) { |
@Override |
||||||
wasOkSelected = false; |
public void actionPerformed(ActionEvent ae) { |
||||||
wasClearSelected = true; |
wasOkSelected = false; |
||||||
performClear(); |
wasClearSelected = true; |
||||||
} |
performClear(); |
||||||
}); |
} |
||||||
addAfterCancel(btnClear); |
}); |
||||||
} |
addAfterCancel(btnClear); |
||||||
public boolean wasClearSelected() { |
} |
||||||
return wasClearSelected; |
|
||||||
} |
public boolean wasClearSelected() { |
||||||
protected abstract void performClear(); |
return wasClearSelected; |
||||||
public static void main(String[] args) { |
} |
||||||
|
|
||||||
OkCancelClearDlg dlg = new OkCancelClearDlg(new JFrame(), "test") { |
protected abstract void performClear(); |
||||||
protected void performOk() { |
|
||||||
} |
public static void main(String[] args) { |
||||||
|
|
||||||
protected void performCancel() { |
OkCancelClearDlg dlg = new OkCancelClearDlg(new JFrame(), "test") { |
||||||
} |
|
||||||
|
@Override |
||||||
protected void performClear() { |
protected void performOk() { |
||||||
} |
} |
||||||
}; |
|
||||||
|
@Override |
||||||
// dlg.addAboveOK(new JLabel("bla"));
|
protected void performCancel() { |
||||||
dlg.setCenter(new JLabel("cnter")); |
} |
||||||
dlg.pack(); |
|
||||||
dlg.show(); |
@Override |
||||||
} |
protected void performClear() { |
||||||
} |
} |
||||||
|
}; |
||||||
|
|
||||||
|
// dlg.addAboveOK(new JLabel("bla"));
|
||||||
|
dlg.setCenter(new JLabel("cnter")); |
||||||
|
dlg.pack(); |
||||||
|
dlg.show(); |
||||||
|
} |
||||||
|
} |
||||||
|
|||||||
@ -1,200 +1,205 @@ |
|||||||
package de.memtext.dlg; |
package de.memtext.dlg; |
||||||
|
|
||||||
import java.awt.BorderLayout; |
import java.awt.BorderLayout; |
||||||
import java.awt.Dialog; |
import java.awt.Dialog; |
||||||
import java.awt.Frame; |
import java.awt.Frame; |
||||||
import java.awt.HeadlessException; |
import java.awt.HeadlessException; |
||||||
import java.awt.event.ActionEvent; |
import java.awt.event.ActionEvent; |
||||||
import java.awt.event.ActionListener; |
import java.awt.event.ActionListener; |
||||||
|
|
||||||
import javax.swing.JComponent; |
import javax.swing.JComponent; |
||||||
import javax.swing.JFrame; |
import javax.swing.JFrame; |
||||||
import javax.swing.JLabel; |
import javax.swing.JLabel; |
||||||
|
|
||||||
import de.memtext.widgets.HorizontalBox; |
import de.memtext.widgets.HorizontalBox; |
||||||
import de.memtext.widgets.VerticalBox; |
import de.memtext.widgets.VerticalBox; |
||||||
|
|
||||||
/** |
/** |
||||||
* Abstract Dialog in which OK or Cancel can be clicked. |
* Abstract Dialog in which OK or Cancel can be clicked. |
||||||
* Subclasses must implement performCancel and performOk. |
* Subclasses must implement performCancel and performOk. |
||||||
* setCenter for convenience. |
* setCenter for convenience. |
||||||
* |
* |
||||||
It's important that clients don't call |
It's important that clients don't call |
||||||
getContentPane().setLayout(new BorderLayout()) or something like that, |
getContentPane().setLayout(new BorderLayout()) or something like that, |
||||||
because that will cause southPanel to disappear |
because that will cause southPanel to disappear |
||||||
*/ |
*/ |
||||||
public abstract class OkCancelDlg |
public abstract class OkCancelDlg extends DialogWithExit { |
||||||
extends DialogWithExit |
private OkCancelPanel pOkCancel; |
||||||
{ |
|
||||||
private OkCancelPanel pOkCancel; |
private HorizontalBox boxAboverOkCancel = new HorizontalBox(); |
||||||
private HorizontalBox boxAboverOkCancel = new HorizontalBox(); |
|
||||||
protected boolean wasOkSelected,wasCancelSelected; |
protected boolean wasOkSelected, wasCancelSelected; |
||||||
public OkCancelDlg(Frame owner, String title, boolean isModal) { |
|
||||||
super(owner, title, isModal); |
public OkCancelDlg(Frame owner, String title, boolean isModal) { |
||||||
initOkCancelDlg(); |
super(owner, title, isModal); |
||||||
} |
initOkCancelDlg(); |
||||||
|
} |
||||||
/** |
|
||||||
* Constructor for OkCancelDlg. |
/** |
||||||
* @param arg0 |
* Constructor for OkCancelDlg. |
||||||
* @param arg1 |
* @param arg0 |
||||||
* @param arg2 |
* @param arg1 |
||||||
* @throws HeadlessException |
* @param arg2 |
||||||
*/ |
* @throws HeadlessException |
||||||
public OkCancelDlg(Frame frame, String title) throws HeadlessException { |
*/ |
||||||
super(frame, title, true); |
public OkCancelDlg(Frame frame, String title) throws HeadlessException { |
||||||
initOkCancelDlg(); |
super(frame, title, true); |
||||||
} |
initOkCancelDlg(); |
||||||
|
} |
||||||
/** |
|
||||||
* Constructor for OkCancelDlg. |
/** |
||||||
* @param arg0 |
* Constructor for OkCancelDlg. |
||||||
* @throws HeadlessException |
* @param arg0 |
||||||
*/ |
* @throws HeadlessException |
||||||
public OkCancelDlg(Dialog arg0) throws HeadlessException { |
*/ |
||||||
super(arg0, true); |
public OkCancelDlg(Dialog arg0) throws HeadlessException { |
||||||
initOkCancelDlg(); |
super(arg0, true); |
||||||
} |
initOkCancelDlg(); |
||||||
|
} |
||||||
/** |
|
||||||
* Constructor for OkCancelDlg. |
/** |
||||||
* @param arg0 |
* Constructor for OkCancelDlg. |
||||||
* @param arg1 |
* @param arg0 |
||||||
* @throws HeadlessException |
* @param arg1 |
||||||
*/ |
* @throws HeadlessException |
||||||
public OkCancelDlg(Dialog arg0, String arg1) throws HeadlessException { |
*/ |
||||||
super(arg0, arg1, true); |
public OkCancelDlg(Dialog arg0, String arg1) throws HeadlessException { |
||||||
initOkCancelDlg(); |
super(arg0, arg1, true); |
||||||
} |
initOkCancelDlg(); |
||||||
|
} |
||||||
private void initOkCancelDlg() { |
|
||||||
//this.setContentPane(new OneTimeInitContentPane());
|
private void initOkCancelDlg() { |
||||||
VerticalBox pSouth = new VerticalBox(); |
//this.setContentPane(new OneTimeInitContentPane());
|
||||||
pOkCancel = new OkCancelPanel(); |
VerticalBox pSouth = new VerticalBox(); |
||||||
pSouth.add(boxAboverOkCancel); |
pOkCancel = new OkCancelPanel(); |
||||||
pSouth.add(pOkCancel); |
pSouth.add(boxAboverOkCancel); |
||||||
|
pSouth.add(pOkCancel); |
||||||
this.getContentPane().add(pSouth, BorderLayout.SOUTH); |
|
||||||
pOkCancel.addActionListener(new ActionListener(){ |
this.getContentPane().add(pSouth, BorderLayout.SOUTH); |
||||||
public void actionPerformed(ActionEvent ae) |
pOkCancel.addActionListener(new ActionListener() { |
||||||
{ |
|
||||||
String cmd = ae.getActionCommand(); |
@Override |
||||||
if (cmd.equals("OK")) { |
public void actionPerformed(ActionEvent ae) { |
||||||
wasOkSelected = true; |
String cmd = ae.getActionCommand(); |
||||||
wasCancelSelected=false; |
if (cmd.equals("OK")) { |
||||||
performOk(); |
wasOkSelected = true; |
||||||
} |
wasCancelSelected = false; |
||||||
|
performOk(); |
||||||
if (cmd.equals("Cancel")) { |
} |
||||||
wasOkSelected = false; |
|
||||||
wasCancelSelected=true; |
if (cmd.equals("Cancel")) { |
||||||
performCancel(); |
wasOkSelected = false; |
||||||
} |
wasCancelSelected = true; |
||||||
} |
performCancel(); |
||||||
}); |
} |
||||||
this.getRootPane().setDefaultButton(pOkCancel.getBtnOk()); |
} |
||||||
} |
}); |
||||||
public void addAboveOK(JComponent comp) { |
this.getRootPane().setDefaultButton(pOkCancel.getBtnOk()); |
||||||
boxAboverOkCancel.add(comp); |
} |
||||||
} |
|
||||||
|
public void addAboveOK(JComponent comp) { |
||||||
public boolean wasOkSelected() { |
boxAboverOkCancel.add(comp); |
||||||
return wasOkSelected; |
} |
||||||
} |
|
||||||
public boolean wasCancelSelected() { |
public boolean wasOkSelected() { |
||||||
return wasCancelSelected; |
return wasOkSelected; |
||||||
} |
} |
||||||
/** |
|
||||||
* subclasses must implement this method and specify commands |
public boolean wasCancelSelected() { |
||||||
* to be executed when OK was clicked |
return wasCancelSelected; |
||||||
*/ |
} |
||||||
protected abstract void performOk(); |
|
||||||
/** |
/** |
||||||
* subclasses must implement this method and specify commands |
* subclasses must implement this method and specify commands |
||||||
* to be executed when Cancel was clicked |
* to be executed when OK was clicked |
||||||
* |
*/ |
||||||
*/ |
protected abstract void performOk(); |
||||||
protected abstract void performCancel(); |
|
||||||
/** |
/** |
||||||
* Adds a Component before the OK button |
* subclasses must implement this method and specify commands |
||||||
* @param comp |
* to be executed when Cancel was clicked |
||||||
*/ |
* |
||||||
public void addBeforeOK(JComponent comp) { |
*/ |
||||||
int pos = |
protected abstract void performCancel(); |
||||||
de.memtext.util.ComponentUtils.getPositionOnComponent( |
|
||||||
pOkCancel.getBtnOk(), |
/** |
||||||
pOkCancel); |
* Adds a Component before the OK button |
||||||
pOkCancel.add(comp, pos); |
* @param comp |
||||||
} |
*/ |
||||||
/** |
public void addBeforeOK(JComponent comp) { |
||||||
* Adds a component right of the OK Button |
int pos = de.memtext.util.ComponentUtils.getPositionOnComponent(pOkCancel.getBtnOk(), pOkCancel); |
||||||
* @param comp |
pOkCancel.add(comp, pos); |
||||||
*/ |
} |
||||||
public void addAfterOK(JComponent comp) { |
|
||||||
int pos = |
/** |
||||||
de.memtext.util.ComponentUtils.getPositionOnComponent( |
* Adds a component right of the OK Button |
||||||
pOkCancel.getBtnOk(), |
* @param comp |
||||||
pOkCancel); |
*/ |
||||||
pOkCancel.add(comp, pos + 1); |
public void addAfterOK(JComponent comp) { |
||||||
} |
int pos = de.memtext.util.ComponentUtils.getPositionOnComponent(pOkCancel.getBtnOk(), pOkCancel); |
||||||
/** |
pOkCancel.add(comp, pos + 1); |
||||||
* Adds a component right of the Cancel Button |
} |
||||||
* @param comp |
|
||||||
*/ |
/** |
||||||
public void addAfterCancel(JComponent comp) { |
* Adds a component right of the Cancel Button |
||||||
int pos = |
* @param comp |
||||||
de.memtext.util.ComponentUtils.getPositionOnComponent( |
*/ |
||||||
pOkCancel.getBtnCancel(), |
public void addAfterCancel(JComponent comp) { |
||||||
pOkCancel); |
int pos = de.memtext.util.ComponentUtils.getPositionOnComponent(pOkCancel.getBtnCancel(), pOkCancel); |
||||||
pOkCancel.add(comp, pos + 1); |
pOkCancel.add(comp, pos + 1); |
||||||
} |
} |
||||||
/* class OneTimeInitContentPane extends Container { |
/* class OneTimeInitContentPane extends Container { |
||||||
private int setLayoutCount=0; |
private int setLayoutCount=0; |
||||||
public void setLayout(LayoutManager manager) { |
public void setLayout(LayoutManager manager) { |
||||||
if (!(manager instanceof BorderLayout)) { |
if (!(manager instanceof BorderLayout)) { |
||||||
throw new IllegalArgumentException("OKCancel Dlg must have BorderLayout"); |
throw new IllegalArgumentException("OKCancel Dlg must have BorderLayout"); |
||||||
} |
} |
||||||
super.setLayout(manager); |
super.setLayout(manager); |
||||||
setLayoutCount++; |
setLayoutCount++; |
||||||
if (setLayoutCount > 0) { |
if (setLayoutCount > 0) { |
||||||
System.out.println( |
System.out.println( |
||||||
"changing layout may cause problems in OKCancelDlg"); |
"changing layout may cause problems in OKCancelDlg"); |
||||||
|
|
||||||
} |
} |
||||||
} |
} |
||||||
}*/ |
}*/ |
||||||
|
|
||||||
public void setOkVisible(boolean b) { |
public void setOkVisible(boolean b) { |
||||||
pOkCancel.setOkVisible(b); |
pOkCancel.setOkVisible(b); |
||||||
} |
} |
||||||
public void setCancelVisible(boolean b) { |
|
||||||
pOkCancel.setCancelVisible(b); |
public void setCancelVisible(boolean b) { |
||||||
} |
pOkCancel.setCancelVisible(b); |
||||||
public boolean requestFocusForOK() { |
} |
||||||
return pOkCancel.getBtnOk().requestFocusInWindow(); |
|
||||||
} |
public boolean requestFocusForOK() { |
||||||
public void setOkBold(boolean b) { |
return pOkCancel.getBtnOk().requestFocusInWindow(); |
||||||
pOkCancel.setOkBold(b); |
} |
||||||
} |
|
||||||
|
public void setOkBold(boolean b) { |
||||||
public void setOkDefaultButton() { |
pOkCancel.setOkBold(b); |
||||||
this.getRootPane().setDefaultButton(pOkCancel.getBtnOk()); |
} |
||||||
} |
|
||||||
|
public void setOkDefaultButton() { |
||||||
public static void main(String[] args) { |
this.getRootPane().setDefaultButton(pOkCancel.getBtnOk()); |
||||||
|
} |
||||||
OkCancelDlg dlg = new OkCancelDlg(new JFrame(), "test") { |
|
||||||
protected void performOk() { |
public static void main(String[] args) { |
||||||
} |
|
||||||
|
OkCancelDlg dlg = new OkCancelDlg(new JFrame(), "test") { |
||||||
protected void performCancel() { |
@Override |
||||||
} |
protected void performOk() { |
||||||
}; |
} |
||||||
|
|
||||||
// dlg.addAboveOK(new JLabel("bla"));
|
@Override |
||||||
dlg.setCenter(new JLabel("cnter")); |
protected void performCancel() { |
||||||
dlg.pack(); |
} |
||||||
dlg.show(); |
}; |
||||||
} |
|
||||||
|
// dlg.addAboveOK(new JLabel("bla"));
|
||||||
} |
dlg.setCenter(new JLabel("cnter")); |
||||||
|
dlg.pack(); |
||||||
|
dlg.show(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|||||||
@ -1,56 +1,61 @@ |
|||||||
package de.memtext.dlg; |
package de.memtext.dlg; |
||||||
|
|
||||||
import java.awt.Font; |
import java.awt.Font; |
||||||
import java.awt.event.ActionListener; |
import java.awt.event.ActionListener; |
||||||
|
|
||||||
import javax.swing.JButton; |
import javax.swing.JButton; |
||||||
import javax.swing.JPanel; |
import javax.swing.JPanel; |
||||||
|
|
||||||
/** |
/** |
||||||
A Panel with an OK and a Cancel button. |
A Panel with an OK and a Cancel button. |
||||||
*/ |
*/ |
||||||
public class OkCancelPanel extends JPanel { |
public class OkCancelPanel extends JPanel { |
||||||
protected JButton btnOk, btnCancel; |
protected JButton btnOk, btnCancel; |
||||||
public OkCancelPanel() { |
|
||||||
btnOk = new JButton("OK"); |
public OkCancelPanel() { |
||||||
btnCancel = new JButton("Abbrechen"); |
btnOk = new JButton("OK"); |
||||||
btnCancel.setActionCommand("Cancel"); |
btnCancel = new JButton("Abbrechen"); |
||||||
add(btnOk); |
btnCancel.setActionCommand("Cancel"); |
||||||
add(btnCancel); |
add(btnOk); |
||||||
|
add(btnCancel); |
||||||
} |
|
||||||
public void addActionListener(ActionListener al) { |
} |
||||||
btnOk.addActionListener(al); |
|
||||||
btnCancel.addActionListener(al); |
public void addActionListener(ActionListener al) { |
||||||
} |
btnOk.addActionListener(al); |
||||||
|
btnCancel.addActionListener(al); |
||||||
/** |
} |
||||||
* Returns the btnCancel. |
|
||||||
* @return JButton |
/** |
||||||
*/ |
* Returns the btnCancel. |
||||||
public JButton getBtnCancel() { |
* @return JButton |
||||||
return btnCancel; |
*/ |
||||||
} |
public JButton getBtnCancel() { |
||||||
|
return btnCancel; |
||||||
/** |
} |
||||||
* Returns the btnOk. |
|
||||||
* @return JButton |
/** |
||||||
*/ |
* Returns the btnOk. |
||||||
public JButton getBtnOk() { |
* @return JButton |
||||||
return btnOk; |
*/ |
||||||
} |
public JButton getBtnOk() { |
||||||
public void setOkVisible(boolean b) { |
return btnOk; |
||||||
btnOk.setVisible(b); |
} |
||||||
} |
|
||||||
public void setCancelVisible(boolean b) { |
public void setOkVisible(boolean b) { |
||||||
btnCancel.setVisible(b); |
btnOk.setVisible(b); |
||||||
} |
} |
||||||
public void setOkBold(boolean b) { |
|
||||||
Font f=btnOk.getFont(); |
public void setCancelVisible(boolean b) { |
||||||
if (b) |
btnCancel.setVisible(b); |
||||||
btnOk.setFont(f.deriveFont(Font.BOLD)); |
} |
||||||
else |
|
||||||
btnOk.setFont(f.deriveFont(Font.PLAIN)); |
public void setOkBold(boolean b) { |
||||||
} |
Font f = btnOk.getFont(); |
||||||
|
if (b) |
||||||
} |
btnOk.setFont(f.deriveFont(Font.BOLD)); |
||||||
|
else |
||||||
|
btnOk.setFont(f.deriveFont(Font.PLAIN)); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|||||||
@ -1,106 +1,109 @@ |
|||||||
package de.memtext.dlg; |
package de.memtext.dlg; |
||||||
|
|
||||||
import java.awt.BorderLayout; |
import java.awt.BorderLayout; |
||||||
import java.awt.Container; |
import java.awt.Container; |
||||||
import java.awt.Dialog; |
import java.awt.Dialog; |
||||||
import java.awt.Frame; |
import java.awt.Frame; |
||||||
import java.awt.HeadlessException; |
import java.awt.HeadlessException; |
||||||
import java.awt.event.ActionEvent; |
import java.awt.event.ActionEvent; |
||||||
import java.awt.event.ActionListener; |
import java.awt.event.ActionListener; |
||||||
|
|
||||||
import javax.swing.JButton; |
import javax.swing.JButton; |
||||||
import javax.swing.JComponent; |
import javax.swing.JComponent; |
||||||
import javax.swing.JPanel; |
import javax.swing.JPanel; |
||||||
/** |
|
||||||
* Dialog which can only be closed by clicking OK. |
/** |
||||||
* |
* Dialog which can only be closed by clicking OK. |
||||||
* setCenter for convenienance. |
* |
||||||
* |
* setCenter for convenienance. |
||||||
* @author MB |
* |
||||||
* |
* @author MB |
||||||
*/ |
* |
||||||
|
*/ |
||||||
public class OkDlg extends DialogWithExit { |
|
||||||
private JPanel psouth = new JPanel(); |
public class OkDlg extends DialogWithExit { |
||||||
protected JButton ok = new JButton("OK"); |
private JPanel psouth = new JPanel(); |
||||||
|
|
||||||
/** |
protected JButton ok = new JButton("OK"); |
||||||
* Constructor for OkDlg. |
|
||||||
* @param arg0 |
/** |
||||||
* @throws HeadlessException |
* Constructor for OkDlg. |
||||||
*/ |
* @param arg0 |
||||||
public OkDlg(Frame owner) throws HeadlessException { |
* @throws HeadlessException |
||||||
super(owner,true); |
*/ |
||||||
initSouth(); |
public OkDlg(Frame owner) throws HeadlessException { |
||||||
} |
super(owner, true); |
||||||
public OkDlg(Frame owner, String title, boolean isModal) { |
initSouth(); |
||||||
super(owner,title,isModal); |
} |
||||||
initSouth(); |
|
||||||
} |
public OkDlg(Frame owner, String title, boolean isModal) { |
||||||
|
super(owner, title, isModal); |
||||||
|
initSouth(); |
||||||
public OkDlg(Frame owner, String title) throws HeadlessException { |
} |
||||||
super(owner, title,true); |
|
||||||
initSouth(); |
|
||||||
} |
public OkDlg(Frame owner, String title) throws HeadlessException { |
||||||
|
super(owner, title, true); |
||||||
|
initSouth(); |
||||||
public JButton getOkBtn() |
} |
||||||
{ |
|
||||||
return ok; |
|
||||||
} |
public JButton getOkBtn() { |
||||||
|
return ok; |
||||||
|
} |
||||||
/** |
|
||||||
* Constructor for OkDlg. |
|
||||||
* @param arg0 |
/** |
||||||
* @throws HeadlessException |
* Constructor for OkDlg. |
||||||
*/ |
* @param arg0 |
||||||
public OkDlg(Dialog arg0) throws HeadlessException { |
* @throws HeadlessException |
||||||
super(arg0,true); |
*/ |
||||||
initSouth(); |
public OkDlg(Dialog arg0) throws HeadlessException { |
||||||
} |
super(arg0, true); |
||||||
|
initSouth(); |
||||||
|
} |
||||||
private void initSouth() { |
|
||||||
|
|
||||||
ok.addActionListener(new ActionListener(){ |
private void initSouth() { |
||||||
public void actionPerformed(ActionEvent ae) |
|
||||||
{ |
ok.addActionListener(new ActionListener() { |
||||||
performOk(); |
|
||||||
} |
@Override |
||||||
}); |
public void actionPerformed(ActionEvent ae) { |
||||||
psouth.add(ok); |
performOk(); |
||||||
|
} |
||||||
Container cp = this.getContentPane(); |
}); |
||||||
cp.add(psouth, BorderLayout.SOUTH); |
psouth.add(ok); |
||||||
this.getRootPane().setDefaultButton(ok); |
|
||||||
|
Container cp = this.getContentPane(); |
||||||
} |
cp.add(psouth, BorderLayout.SOUTH); |
||||||
|
this.getRootPane().setDefaultButton(ok); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
public void addBeforeOK(JComponent comp) { |
|
||||||
int pos = |
|
||||||
de.memtext.util.ComponentUtils.getPositionOnComponent(ok, psouth); |
|
||||||
psouth.add(comp, pos); |
public void addBeforeOK(JComponent comp) { |
||||||
} |
int pos = de.memtext.util.ComponentUtils.getPositionOnComponent(ok, psouth); |
||||||
public void addAfterOK(JComponent comp) { |
psouth.add(comp, pos); |
||||||
int pos = |
} |
||||||
de.memtext.util.ComponentUtils.getPositionOnComponent(ok, psouth); |
|
||||||
psouth.add(comp, pos+1); |
public void addAfterOK(JComponent comp) { |
||||||
} |
int pos = de.memtext.util.ComponentUtils.getPositionOnComponent(ok, psouth); |
||||||
/** |
psouth.add(comp, pos + 1); |
||||||
* subclasses can override this method and specify commands |
} |
||||||
* to be executed when OK was clicked |
|
||||||
*/ |
/** |
||||||
protected void performOk() |
* subclasses can override this method and specify commands |
||||||
{ |
* to be executed when OK was clicked |
||||||
this.hide(); |
*/ |
||||||
} |
protected void performOk() { |
||||||
public static void main(String args[]) { |
this.hide(); |
||||||
OkDlg d=new OkDlg(new javax.swing.JFrame()); |
} |
||||||
d.show(); |
|
||||||
} |
public static void main(String args[]) { |
||||||
} |
OkDlg d = new OkDlg(new javax.swing.JFrame()); |
||||||
|
d.show(); |
||||||
|
} |
||||||
|
} |
||||||
|
|||||||
@ -1,185 +1,177 @@ |
|||||||
package de.memtext.dlg; |
package de.memtext.dlg; |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import java.awt.BorderLayout; |
import java.awt.BorderLayout; |
||||||
import java.awt.Container; |
import java.awt.Container; |
||||||
import java.awt.Dialog; |
import java.awt.Dialog; |
||||||
import java.awt.Frame; |
import java.awt.Frame; |
||||||
import java.awt.GraphicsConfiguration; |
import java.awt.GraphicsConfiguration; |
||||||
import java.awt.HeadlessException; |
import java.awt.HeadlessException; |
||||||
import java.awt.event.ActionEvent; |
import java.awt.event.ActionEvent; |
||||||
import java.awt.event.ActionListener; |
import java.awt.event.ActionListener; |
||||||
|
|
||||||
|
|
||||||
/** |
/** |
||||||
A abstract dialog with OK and DONE buttons. Subclasses must implement |
A abstract dialog with OK and DONE buttons. Subclasses must implement |
||||||
performDone() and performOK(); |
performDone() and performOK(); |
||||||
*/ |
*/ |
||||||
public abstract class OkDoneDlg extends DialogWithExit { |
public abstract class OkDoneDlg extends DialogWithExit { |
||||||
/** |
/** |
||||||
* Constructor for OkDoneDlg. |
* Constructor for OkDoneDlg. |
||||||
* @throws HeadlessException |
* @throws HeadlessException |
||||||
*/ |
*/ |
||||||
public OkDoneDlg() throws HeadlessException { |
public OkDoneDlg() throws HeadlessException { |
||||||
super(); |
super(); |
||||||
initSouth(); |
initSouth(); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* Constructor for OkDoneDlg. |
* Constructor for OkDoneDlg. |
||||||
* @param arg0 |
* @param arg0 |
||||||
* @throws HeadlessException |
* @throws HeadlessException |
||||||
*/ |
*/ |
||||||
public OkDoneDlg(Frame arg0) throws HeadlessException { |
public OkDoneDlg(Frame arg0) throws HeadlessException { |
||||||
super(arg0); |
super(arg0); |
||||||
initSouth(); |
initSouth(); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* Constructor for OkDoneDlg. |
* Constructor for OkDoneDlg. |
||||||
* @param arg0 |
* @param arg0 |
||||||
* @param arg1 |
* @param arg1 |
||||||
* @throws HeadlessException |
* @throws HeadlessException |
||||||
*/ |
*/ |
||||||
public OkDoneDlg(Frame arg0, boolean arg1) throws HeadlessException { |
public OkDoneDlg(Frame arg0, boolean arg1) throws HeadlessException { |
||||||
super(arg0, arg1); |
super(arg0, arg1); |
||||||
initSouth(); |
initSouth(); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* Constructor for OkDoneDlg. |
* Constructor for OkDoneDlg. |
||||||
* @param arg0 |
* @param arg0 |
||||||
* @param arg1 |
* @param arg1 |
||||||
* @throws HeadlessException |
* @throws HeadlessException |
||||||
*/ |
*/ |
||||||
public OkDoneDlg(Frame arg0, String arg1) throws HeadlessException { |
public OkDoneDlg(Frame arg0, String arg1) throws HeadlessException { |
||||||
super(arg0, arg1); |
super(arg0, arg1); |
||||||
initSouth(); |
initSouth(); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* Constructor for OkDoneDlg. |
* Constructor for OkDoneDlg. |
||||||
* @param arg0 |
* @param arg0 |
||||||
* @param arg1 |
* @param arg1 |
||||||
* @param arg2 |
* @param arg2 |
||||||
* @throws HeadlessException |
* @throws HeadlessException |
||||||
*/ |
*/ |
||||||
public OkDoneDlg(Frame arg0, String arg1, boolean arg2) |
public OkDoneDlg(Frame arg0, String arg1, boolean arg2) throws HeadlessException { |
||||||
throws HeadlessException { |
super(arg0, arg1, arg2); |
||||||
super(arg0, arg1, arg2); |
initSouth(); |
||||||
initSouth(); |
} |
||||||
} |
|
||||||
|
/** |
||||||
/** |
* Constructor for OkDoneDlg. |
||||||
* Constructor for OkDoneDlg. |
* @param arg0 |
||||||
* @param arg0 |
* @param arg1 |
||||||
* @param arg1 |
* @param arg2 |
||||||
* @param arg2 |
* @param arg3 |
||||||
* @param arg3 |
*/ |
||||||
*/ |
public OkDoneDlg(Frame arg0, String arg1, boolean arg2, GraphicsConfiguration arg3) { |
||||||
public OkDoneDlg( |
super(arg0, arg1, arg2, arg3); |
||||||
Frame arg0, |
initSouth(); |
||||||
String arg1, |
} |
||||||
boolean arg2, |
|
||||||
GraphicsConfiguration arg3) { |
/** |
||||||
super(arg0, arg1, arg2, arg3); |
* Constructor for OkDoneDlg. |
||||||
initSouth(); |
* @param arg0 |
||||||
} |
* @throws HeadlessException |
||||||
|
*/ |
||||||
/** |
public OkDoneDlg(Dialog arg0) throws HeadlessException { |
||||||
* Constructor for OkDoneDlg. |
super(arg0); |
||||||
* @param arg0 |
initSouth(); |
||||||
* @throws HeadlessException |
} |
||||||
*/ |
|
||||||
public OkDoneDlg(Dialog arg0) throws HeadlessException { |
/** |
||||||
super(arg0); |
* Constructor for OkDoneDlg. |
||||||
initSouth(); |
* @param arg0 |
||||||
} |
* @param arg1 |
||||||
|
* @throws HeadlessException |
||||||
/** |
*/ |
||||||
* Constructor for OkDoneDlg. |
public OkDoneDlg(Dialog arg0, boolean arg1) throws HeadlessException { |
||||||
* @param arg0 |
super(arg0, arg1); |
||||||
* @param arg1 |
initSouth(); |
||||||
* @throws HeadlessException |
} |
||||||
*/ |
|
||||||
public OkDoneDlg(Dialog arg0, boolean arg1) throws HeadlessException { |
/** |
||||||
super(arg0, arg1); |
* Constructor for OkDoneDlg. |
||||||
initSouth(); |
* @param arg0 |
||||||
} |
* @param arg1 |
||||||
|
* @throws HeadlessException |
||||||
/** |
*/ |
||||||
* Constructor for OkDoneDlg. |
public OkDoneDlg(Dialog arg0, String arg1) throws HeadlessException { |
||||||
* @param arg0 |
super(arg0, arg1); |
||||||
* @param arg1 |
initSouth(); |
||||||
* @throws HeadlessException |
} |
||||||
*/ |
|
||||||
public OkDoneDlg(Dialog arg0, String arg1) throws HeadlessException { |
/** |
||||||
super(arg0, arg1); |
* Constructor for OkDoneDlg. |
||||||
initSouth(); |
* @param arg0 |
||||||
} |
* @param arg1 |
||||||
|
* @param arg2 |
||||||
/** |
* @throws HeadlessException |
||||||
* Constructor for OkDoneDlg. |
*/ |
||||||
* @param arg0 |
public OkDoneDlg(Dialog arg0, String arg1, boolean arg2) throws HeadlessException { |
||||||
* @param arg1 |
super(arg0, arg1, arg2); |
||||||
* @param arg2 |
initSouth(); |
||||||
* @throws HeadlessException |
} |
||||||
*/ |
|
||||||
public OkDoneDlg(Dialog arg0, String arg1, boolean arg2) |
/** |
||||||
throws HeadlessException { |
* Constructor for OkDoneDlg. |
||||||
super(arg0, arg1, arg2); |
* @param arg0 |
||||||
initSouth(); |
* @param arg1 |
||||||
} |
* @param arg2 |
||||||
|
* @param arg3 |
||||||
/** |
* @throws HeadlessException |
||||||
* Constructor for OkDoneDlg. |
*/ |
||||||
* @param arg0 |
public OkDoneDlg(Dialog arg0, String arg1, boolean arg2, GraphicsConfiguration arg3) throws HeadlessException { |
||||||
* @param arg1 |
super(arg0, arg1, arg2, arg3); |
||||||
* @param arg2 |
initSouth(); |
||||||
* @param arg3 |
} |
||||||
* @throws HeadlessException |
|
||||||
*/ |
private void initSouth() { |
||||||
public OkDoneDlg( |
OkCancelPanel ocp = new OkCancelPanel(); |
||||||
Dialog arg0, |
Container cp = this.getContentPane(); |
||||||
String arg1, |
cp.add(ocp, BorderLayout.SOUTH); |
||||||
boolean arg2, |
ocp.addActionListener(new ActionListener() { |
||||||
GraphicsConfiguration arg3) |
|
||||||
throws HeadlessException { |
@Override |
||||||
super(arg0, arg1, arg2, arg3); |
public void actionPerformed(ActionEvent ae) { |
||||||
initSouth(); |
String cmd = ae.getActionCommand(); |
||||||
} |
if (cmd.equals("OK")) { |
||||||
|
performOk(); |
||||||
private void initSouth() { |
} |
||||||
OkCancelPanel ocp = new OkCancelPanel(); |
|
||||||
Container cp = this.getContentPane(); |
if (cmd.equals("Done")) { |
||||||
cp.add(ocp, BorderLayout.SOUTH); |
performDone(); |
||||||
ocp.addActionListener(new ActionListener(){ |
} |
||||||
public void actionPerformed(ActionEvent ae) |
} |
||||||
{ |
}); |
||||||
String cmd = ae.getActionCommand(); |
; |
||||||
if (cmd.equals("OK")) { |
} |
||||||
performOk(); |
|
||||||
} |
|
||||||
|
/** |
||||||
if (cmd.equals("Done")) { |
* subclasses must implement this method and specify commands |
||||||
performDone(); |
* to be executed when OK was clicked |
||||||
} |
*/ |
||||||
} |
protected abstract void performOk(); |
||||||
});; |
|
||||||
} |
/** |
||||||
|
* subclasses must implement this method and specify commands |
||||||
|
* to be executed when DONE was clicked |
||||||
/** |
*/ |
||||||
* subclasses must implement this method and specify commands |
|
||||||
* to be executed when OK was clicked |
protected abstract void performDone(); |
||||||
*/ |
} |
||||||
protected abstract void performOk(); |
|
||||||
/** |
|
||||||
* subclasses must implement this method and specify commands |
|
||||||
* to be executed when DONE was clicked |
|
||||||
*/ |
|
||||||
|
|
||||||
protected abstract void performDone(); |
|
||||||
} |
|
||||||
|
|||||||
@ -1,32 +1,32 @@ |
|||||||
package de.memtext.dlg; |
package de.memtext.dlg; |
||||||
|
|
||||||
import java.awt.event.ActionListener; |
import java.awt.event.ActionListener; |
||||||
|
|
||||||
import javax.swing.JButton; |
import javax.swing.JButton; |
||||||
import javax.swing.JPanel; |
import javax.swing.JPanel; |
||||||
|
|
||||||
/** |
/** |
||||||
* @author MB |
* @author MB |
||||||
* |
* |
||||||
* To change this generated comment edit the template variable "typecomment": |
* To change this generated comment edit the template variable "typecomment": |
||||||
* Window>Preferences>Java>Templates. |
* Window>Preferences>Java>Templates. |
||||||
* To enable and disable the creation of type comments go to |
* To enable and disable the creation of type comments go to |
||||||
* Window>Preferences>Java>Code Generation. |
* Window>Preferences>Java>Code Generation. |
||||||
*/ |
*/ |
||||||
public class OkDonePanel extends JPanel { |
public class OkDonePanel extends JPanel { |
||||||
JButton btnOk,btnDone; |
JButton btnOk, btnDone; |
||||||
public OkDonePanel() |
|
||||||
{ |
public OkDonePanel() { |
||||||
btnOk=new JButton("OK"); |
btnOk = new JButton("OK"); |
||||||
btnDone=new JButton("Fertig"); |
btnDone = new JButton("Fertig"); |
||||||
add(btnOk); |
add(btnOk); |
||||||
add(btnDone); |
add(btnDone); |
||||||
} |
} |
||||||
public void addActionListener(ActionListener al) |
|
||||||
{ |
public void addActionListener(ActionListener al) { |
||||||
btnOk.addActionListener(al); |
btnOk.addActionListener(al); |
||||||
btnDone.addActionListener(al); |
btnDone.addActionListener(al); |
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
} |
} |
||||||
|
|||||||
@ -1,185 +1,199 @@ |
|||||||
package de.memtext.dlg; |
package de.memtext.dlg; |
||||||
|
|
||||||
import java.awt.Dimension; |
import java.awt.Dimension; |
||||||
import java.awt.Font; |
import java.awt.Font; |
||||||
import java.awt.Frame; |
import java.awt.Frame; |
||||||
import java.awt.GridLayout; |
import java.awt.GridLayout; |
||||||
import java.awt.event.KeyEvent; |
import java.awt.event.KeyEvent; |
||||||
|
|
||||||
import javax.swing.JLabel; |
import javax.swing.JLabel; |
||||||
import javax.swing.JPanel; |
import javax.swing.JPanel; |
||||||
import javax.swing.JPasswordField; |
import javax.swing.JPasswordField; |
||||||
import javax.swing.JTextField; |
import javax.swing.JTextField; |
||||||
import javax.swing.KeyStroke; |
import javax.swing.KeyStroke; |
||||||
|
|
||||||
import de.memtext.rights.NewPasswordChecker; |
import de.memtext.rights.NewPasswordChecker; |
||||||
import de.memtext.util.WindowUtils; |
import de.memtext.util.WindowUtils; |
||||||
import de.memtext.widgets.HorizontalBox; |
import de.memtext.widgets.HorizontalBox; |
||||||
import de.memtext.widgets.WarningMessage; |
import de.memtext.widgets.WarningMessage; |
||||||
|
|
||||||
public abstract class PasswdChangeDlg extends OkCancelDlg { |
public abstract class PasswdChangeDlg extends OkCancelDlg { |
||||||
private JLabel lblInfoDummy=new JLabel(); |
private JLabel lblInfoDummy = new JLabel(); |
||||||
private NewPasswordChecker newPasswordChecker; |
|
||||||
private boolean isCheckOldPasswdWanted = true,isNewPasswordRequired=true; |
private NewPasswordChecker newPasswordChecker; |
||||||
private JTextField usernameField = new JTextField(20); |
|
||||||
private KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0); |
private boolean isCheckOldPasswdWanted = true, isNewPasswordRequired = true; |
||||||
private JLabel lblInfo=new JLabel(); |
|
||||||
private JLabel lbl0 = new JLabel("Username:", JLabel.RIGHT); |
private JTextField usernameField = new JTextField(20); |
||||||
private JLabel lbl1 = new JLabel("altes Passwort:", JLabel.RIGHT); |
|
||||||
private JPasswordField oldpasswField = new JPasswordField(30); |
private KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0); |
||||||
private JLabel lbl2 = new JLabel("neues Passwort:", JLabel.RIGHT); |
|
||||||
private JPasswordField newpasswField = new JPasswordField(30); |
private JLabel lblInfo = new JLabel(); |
||||||
private JLabel lbl3 = new JLabel("wiederholen:", JLabel.RIGHT); |
|
||||||
private JPasswordField newpasswField2 = new JPasswordField(30); |
private JLabel lbl0 = new JLabel("Username:", JLabel.RIGHT); |
||||||
|
|
||||||
public PasswdChangeDlg(Frame frame, String title) { |
private JLabel lbl1 = new JLabel("altes Passwort:", JLabel.RIGHT); |
||||||
super(frame, title, true); |
|
||||||
JPanel p=new JPanel(); |
private JPasswordField oldpasswField = new JPasswordField(30); |
||||||
p.add(lblInfo); |
|
||||||
HorizontalBox hbox = new HorizontalBox(); |
private JLabel lbl2 = new JLabel("neues Passwort:", JLabel.RIGHT); |
||||||
JPanel lblPanel = new JPanel(new GridLayout(0, 1)); |
|
||||||
lblPanel.setMaximumSize(new Dimension(150, 100)); |
private JPasswordField newpasswField = new JPasswordField(30); |
||||||
|
|
||||||
|
private JLabel lbl3 = new JLabel("wiederholen:", JLabel.RIGHT); |
||||||
lblPanel.add(lbl0); |
|
||||||
lblPanel.add(lbl1); |
private JPasswordField newpasswField2 = new JPasswordField(30); |
||||||
lblPanel.add(lbl2); |
|
||||||
lblPanel.add(lbl3); |
public PasswdChangeDlg(Frame frame, String title) { |
||||||
|
super(frame, title, true); |
||||||
lblInfo.setVisible(false); |
JPanel p = new JPanel(); |
||||||
hbox.add(lblPanel); |
p.add(lblInfo); |
||||||
JPanel fieldPanel = new JPanel(new GridLayout(0, 1)); |
HorizontalBox hbox = new HorizontalBox(); |
||||||
|
JPanel lblPanel = new JPanel(new GridLayout(0, 1)); |
||||||
fieldPanel.add(usernameField); |
lblPanel.setMaximumSize(new Dimension(150, 100)); |
||||||
usernameField.getKeymap().removeKeyStrokeBinding(enter); |
|
||||||
|
|
||||||
fieldPanel.add(oldpasswField); |
lblPanel.add(lbl0); |
||||||
oldpasswField.getKeymap().removeKeyStrokeBinding(enter); |
lblPanel.add(lbl1); |
||||||
fieldPanel.add(newpasswField); |
lblPanel.add(lbl2); |
||||||
newpasswField.getKeymap().removeKeyStrokeBinding(enter); |
lblPanel.add(lbl3); |
||||||
fieldPanel.add(newpasswField2); |
|
||||||
newpasswField2.getKeymap().removeKeyStrokeBinding(enter); |
lblInfo.setVisible(false); |
||||||
hbox.add(fieldPanel); |
hbox.add(lblPanel); |
||||||
this.setCenter(hbox); |
JPanel fieldPanel = new JPanel(new GridLayout(0, 1)); |
||||||
this.setNorth(p); |
|
||||||
this.pack(); |
fieldPanel.add(usernameField); |
||||||
WindowUtils.center(this); |
usernameField.getKeymap().removeKeyStrokeBinding(enter); |
||||||
} |
|
||||||
public void setNewPasswordChecker(NewPasswordChecker newPasswordChecker) |
fieldPanel.add(oldpasswField); |
||||||
{ |
oldpasswField.getKeymap().removeKeyStrokeBinding(enter); |
||||||
this.newPasswordChecker=newPasswordChecker; |
fieldPanel.add(newpasswField); |
||||||
} |
newpasswField.getKeymap().removeKeyStrokeBinding(enter); |
||||||
public void setUsername(String username) { |
fieldPanel.add(newpasswField2); |
||||||
usernameField.setText(username); |
newpasswField2.getKeymap().removeKeyStrokeBinding(enter); |
||||||
} |
hbox.add(fieldPanel); |
||||||
public void clear() { |
this.setCenter(hbox); |
||||||
usernameField.setText(""); |
this.setNorth(p); |
||||||
oldpasswField.setText(""); |
this.pack(); |
||||||
newpasswField.setText(""); |
WindowUtils.center(this); |
||||||
newpasswField2.setText(""); |
} |
||||||
} |
|
||||||
protected abstract boolean isOldPasswordOK(String username, String passwd); |
public void setNewPasswordChecker(NewPasswordChecker newPasswordChecker) { |
||||||
|
this.newPasswordChecker = newPasswordChecker; |
||||||
/** |
} |
||||||
* wenn OK geklickt wird wird automatisch geprüft ob die Länge des neuen |
|
||||||
* Passwort passt und beide gleich sind |
public void setUsername(String username) { |
||||||
*/ |
usernameField.setText(username); |
||||||
protected final void performOk() { |
} |
||||||
String new1 = new String(newpasswField.getPassword()); |
|
||||||
if (new1==null||new1.length()<4 ) |
public void clear() { |
||||||
{ |
usernameField.setText(""); |
||||||
WarningMessage.show(this, |
oldpasswField.setText(""); |
||||||
"Das neue Passwort ist zu kurz.", |
newpasswField.setText(""); |
||||||
"Achtung"); |
newpasswField2.setText(""); |
||||||
return; |
} |
||||||
} |
|
||||||
|
protected abstract boolean isOldPasswordOK(String username, String passwd); |
||||||
String new2 = new String(newpasswField2.getPassword()); |
|
||||||
String oldPassword = new String(oldpasswField.getPassword()); |
/** |
||||||
if (!new1.equals(new2)) { |
* wenn OK geklickt wird wird automatisch geprüft ob die Länge des neuen |
||||||
WarningMessage.show(this, |
* Passwort passt und beide gleich sind |
||||||
"Die beiden neuen Passwörter stimmen nicht überein", |
*/ |
||||||
"Achtung"); |
@Override |
||||||
return; |
protected final void performOk() { |
||||||
} |
String new1 = new String(newpasswField.getPassword()); |
||||||
String faults=null; |
if (new1 == null || new1.length() < 4) { |
||||||
if (newPasswordChecker!=null) faults=newPasswordChecker.checkForFaults(getUsername(),new String(newpasswField.getPassword())); |
WarningMessage.show(this, "Das neue Passwort ist zu kurz.", "Achtung"); |
||||||
|
return; |
||||||
if (faults!=null) { |
} |
||||||
WarningMessage.show(this, |
|
||||||
faults, |
String new2 = new String(newpasswField2.getPassword()); |
||||||
"Achtung"); |
String oldPassword = new String(oldpasswField.getPassword()); |
||||||
return; |
if (!new1.equals(new2)) { |
||||||
} |
WarningMessage.show(this, "Die beiden neuen Passwörter stimmen nicht überein", "Achtung"); |
||||||
|
return; |
||||||
if (isNewPasswordRequired&&new1.equals(oldPassword)) |
} |
||||||
{ |
String faults = null; |
||||||
WarningMessage.show(this,"Sie müssen ein neues Passwort eingeben","Achtung"); |
if (newPasswordChecker != null) faults = newPasswordChecker.checkForFaults(getUsername(), new String(newpasswField.getPassword())); |
||||||
return; |
|
||||||
} |
if (faults != null) { |
||||||
|
WarningMessage.show(this, faults, "Achtung"); |
||||||
if (isCheckOldPasswdWanted |
return; |
||||||
&& !isOldPasswordOK(usernameField.getText(), |
} |
||||||
oldPassword)) { |
|
||||||
WarningMessage.show(this,"Das alte Passwort stimmt nicht", "Achtung"); |
if (isNewPasswordRequired && new1.equals(oldPassword)) { |
||||||
return; |
WarningMessage.show(this, "Sie müssen ein neues Passwort eingeben", "Achtung"); |
||||||
} |
return; |
||||||
this.hide(); |
} |
||||||
} |
|
||||||
|
if (isCheckOldPasswdWanted && !isOldPasswordOK(usernameField.getText(), oldPassword)) { |
||||||
protected void performCancel() { |
WarningMessage.show(this, "Das alte Passwort stimmt nicht", "Achtung"); |
||||||
this.hide(); |
return; |
||||||
} |
} |
||||||
|
this.hide(); |
||||||
|
} |
||||||
public void setUsernameFieldEnabled(boolean b) { |
|
||||||
usernameField.setEnabled(b); |
@Override |
||||||
} |
protected void performCancel() { |
||||||
public void setOldPassword(String passw) { |
this.hide(); |
||||||
oldpasswField.setText(passw); |
} |
||||||
} |
|
||||||
public String getUsername() { |
|
||||||
return usernameField.getText(); |
public void setUsernameFieldEnabled(boolean b) { |
||||||
} |
usernameField.setEnabled(b); |
||||||
public String getOldPasswd() { |
} |
||||||
return new String(oldpasswField.getPassword()); |
|
||||||
} |
public void setOldPassword(String passw) { |
||||||
public String getNewPasswd() { |
oldpasswField.setText(passw); |
||||||
return new String(newpasswField.getPassword()); |
} |
||||||
} |
|
||||||
public boolean isCheckOldPasswdWanted() { |
public String getUsername() { |
||||||
return isCheckOldPasswdWanted; |
return usernameField.getText(); |
||||||
} |
} |
||||||
|
|
||||||
public void setCheckOldPasswdWanted(boolean b) { |
public String getOldPasswd() { |
||||||
isCheckOldPasswdWanted = b; |
return new String(oldpasswField.getPassword()); |
||||||
lbl1.setVisible(b); |
} |
||||||
oldpasswField.setVisible(b); |
|
||||||
} |
public String getNewPasswd() { |
||||||
public void setInfoLabel(String txt) { |
return new String(newpasswField.getPassword()); |
||||||
lblInfo.setVisible(true); |
} |
||||||
lblInfo.setText(txt); |
|
||||||
lblInfo.setFont(new Font("SansSerif",Font.BOLD,12)); |
public boolean isCheckOldPasswdWanted() { |
||||||
} |
return isCheckOldPasswdWanted; |
||||||
|
} |
||||||
public boolean isNewPasswordRequired() { |
|
||||||
return isNewPasswordRequired; |
public void setCheckOldPasswdWanted(boolean b) { |
||||||
} |
isCheckOldPasswdWanted = b; |
||||||
|
lbl1.setVisible(b); |
||||||
public void setNewPasswordRequired(boolean b) { |
oldpasswField.setVisible(b); |
||||||
isNewPasswordRequired = b; |
} |
||||||
} |
|
||||||
public static void main(String a[]) |
public void setInfoLabel(String txt) { |
||||||
{ |
lblInfo.setVisible(true); |
||||||
PasswdChangeDlg dlg=new PasswdChangeDlg(null,"dummy"){ |
lblInfo.setText(txt); |
||||||
|
lblInfo.setFont(new Font("SansSerif", Font.BOLD, 12)); |
||||||
protected boolean isOldPasswordOK(String username, String passwd) { |
} |
||||||
return false; |
|
||||||
}} |
public boolean isNewPasswordRequired() { |
||||||
; |
return isNewPasswordRequired; |
||||||
dlg.setInfoLabel("bitte ändern"); |
} |
||||||
dlg.show(); |
|
||||||
} |
public void setNewPasswordRequired(boolean b) { |
||||||
} |
isNewPasswordRequired = b; |
||||||
|
} |
||||||
|
|
||||||
|
public static void main(String a[]) { |
||||||
|
PasswdChangeDlg dlg = new PasswdChangeDlg(null, "dummy") { |
||||||
|
|
||||||
|
@Override |
||||||
|
protected boolean isOldPasswordOK(String username, String passwd) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
}; |
||||||
|
dlg.setInfoLabel("bitte ändern"); |
||||||
|
dlg.show(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
//Created on 09.01.2004 at 17:16:16
|
//Created on 09.01.2004 at 17:16:16
|
||||||
@ -1,122 +0,0 @@ |
|||||||
package de.memtext.hbt; |
|
||||||
|
|
||||||
import java.io.IOException; |
|
||||||
import java.sql.SQLException; |
|
||||||
import java.util.logging.Level; |
|
||||||
import java.util.logging.Logger; |
|
||||||
|
|
||||||
import javax.mail.Flags; |
|
||||||
import javax.mail.Folder; |
|
||||||
import javax.mail.Message; |
|
||||||
import javax.mail.MessagingException; |
|
||||||
import javax.mail.search.FlagTerm; |
|
||||||
|
|
||||||
import de.memtext.util.LogUtils; |
|
||||||
import de.superx.servlet.SxMail; |
|
||||||
import de.superx.servlet.SxPool; |
|
||||||
|
|
||||||
public abstract class AbstractAriel extends Thread { |
|
||||||
// this is defined as private static method to use as little memory as possible,
|
|
||||||
// it would be neglectable in moder computers to create it every time the method
|
|
||||||
// runs, GarbargeCollection would easily do the job
|
|
||||||
// yet I define it that way out of respect for the programmers of beginning in
|
|
||||||
// the 50ies/60ies or whenever
|
|
||||||
// private static FlagTerm flagUnseen = new FlagTerm(new Flags(Flags.Flag.SEEN), true); // ja ich weiß, flagUnseen
|
|
||||||
Flags seen = new Flags(Flags.Flag.RECENT); |
|
||||||
private static FlagTerm flagUnseen = new FlagTerm(new Flags(Flags.Flag.SEEN), false); |
|
||||||
static Flags flagsContainingOnlySeen=new Flags(Flags.Flag.SEEN); |
|
||||||
protected Logger logger=null; |
|
||||||
// wird bisher nicht
|
|
||||||
// benötigt, aber ist doch
|
|
||||||
// klar, dass ich das gleich
|
|
||||||
// nutzen will, dass nervt,
|
|
||||||
// dass die Meldung jetzt
|
|
||||||
// kommt
|
|
||||||
private boolean isActive = true; |
|
||||||
private int interval = 10; |
|
||||||
protected SxMail sxmail; |
|
||||||
|
|
||||||
public AbstractAriel() { |
|
||||||
super(); |
|
||||||
} |
|
||||||
|
|
||||||
public AbstractAriel(Runnable target) { |
|
||||||
super(target); |
|
||||||
} |
|
||||||
|
|
||||||
public AbstractAriel(String name) { |
|
||||||
super(name); |
|
||||||
} |
|
||||||
|
|
||||||
public AbstractAriel(ThreadGroup group, Runnable target) { |
|
||||||
super(group, target); |
|
||||||
} |
|
||||||
|
|
||||||
public AbstractAriel(ThreadGroup group, String name) { |
|
||||||
super(group, name); |
|
||||||
} |
|
||||||
|
|
||||||
public AbstractAriel(Runnable target, String name) { |
|
||||||
super(target, name); |
|
||||||
} |
|
||||||
|
|
||||||
public AbstractAriel(ThreadGroup group, Runnable target, String name) { |
|
||||||
super(group, target, name); |
|
||||||
} |
|
||||||
|
|
||||||
public AbstractAriel(ThreadGroup group, Runnable target, String name, long stackSize) { |
|
||||||
super(group, target, name, stackSize); |
|
||||||
} |
|
||||||
|
|
||||||
public void initLogging()throws IOException |
|
||||||
{ |
|
||||||
String filename=SxPool.getLogDir() + "/superx_" |
|
||||||
+ getArielName() + ".log"; |
|
||||||
LogUtils.initRawFile("superx_" + getArielName(), filename, 20000, 1, true, true); |
|
||||||
System.out.println("Superx Mail logging in "+filename); |
|
||||||
logger=Logger.getLogger("superx_" + getArielName()); |
|
||||||
Level lev = Level.SEVERE; |
|
||||||
logger.setLevel(lev); |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} |
|
||||||
public String getArielName() |
|
||||||
{ |
|
||||||
return "mail"; |
|
||||||
} |
|
||||||
public void run() { |
|
||||||
while (isActive) { |
|
||||||
try { |
|
||||||
Thread.sleep(interval * 1000); |
|
||||||
|
|
||||||
} catch (InterruptedException e) { |
|
||||||
// e.printStackTrace();
|
|
||||||
} |
|
||||||
|
|
||||||
try { |
|
||||||
|
|
||||||
logger.log(Level.INFO,"SuperX is checking mails for new heartbeats..."); |
|
||||||
|
|
||||||
|
|
||||||
Folder inbox=sxmail.getInbox(); |
|
||||||
//if (inbox.hasNewMessages())
|
|
||||||
processNewMessages(inbox.getMessages()); // processed messages will be deleted -> don#t need inbox.search(flagUnseen)); // former first attempt was : processNewMessages(inbox.getMessages()); // should be in differnt colour (<- British English)
|
|
||||||
|
|
||||||
sxmail.closeInbox(); //deletes marked mails
|
|
||||||
} catch (Exception e) { |
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace(); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
abstract void processNewMessages(Message[] messages) throws MessagingException, IOException, SQLException; |
|
||||||
|
|
||||||
public void setActive(boolean isActive) { |
|
||||||
this.isActive=isActive; |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
@ -1,96 +0,0 @@ |
|||||||
package de.memtext.hbt; |
|
||||||
|
|
||||||
import java.io.IOException; |
|
||||||
import java.util.Properties; |
|
||||||
|
|
||||||
import javax.mail.Folder; |
|
||||||
import javax.mail.Message; |
|
||||||
import javax.mail.MessagingException; |
|
||||||
import javax.mail.Session; |
|
||||||
import javax.mail.Store; |
|
||||||
import javax.mail.Transport; |
|
||||||
import javax.mail.internet.AddressException; |
|
||||||
import javax.mail.internet.InternetAddress; |
|
||||||
import javax.mail.internet.MimeMessage; |
|
||||||
|
|
||||||
public class Checker { |
|
||||||
|
|
||||||
public static void check(Session emailSession, String user, String password) |
|
||||||
throws MessagingException, IOException { |
|
||||||
|
|
||||||
// create the POP3 store object and connect with the pop server
|
|
||||||
// pop3s wichtig -> vermutlich secure
|
|
||||||
Store store = emailSession.getStore("pop3s"); |
|
||||||
store.connect(emailSession.getProperty("mail.pop3.host"), user, password); |
|
||||||
|
|
||||||
Folder emailFolder = store.getFolder("INBOX"); |
|
||||||
emailFolder.open(Folder.READ_ONLY); |
|
||||||
|
|
||||||
// messages werden geholt, können nur ausgelesen werden, wenn Folder noch open
|
|
||||||
// ist!
|
|
||||||
Message[] messages = emailFolder.getMessages(); |
|
||||||
|
|
||||||
System.out.println("messages.length---" + messages.length); |
|
||||||
|
|
||||||
for (int i = 0, n = messages.length; i < n; i++) { |
|
||||||
Message message = messages[i]; |
|
||||||
System.out.println("---------------------------------"); |
|
||||||
System.out.println("Email Number " + (i + 1)); |
|
||||||
System.out.println("Subject: " + message.getSubject()); |
|
||||||
System.out.println("From: " + message.getFrom()[0]); |
|
||||||
System.out.println("Text: " + message.getContent().toString()); |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
// close the store and folder objects
|
|
||||||
emailFolder.close(false); |
|
||||||
store.close(); |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
private static void send(Session emailSession, String user, String recipient, String subject, String text, |
|
||||||
String password) throws AddressException, MessagingException { |
|
||||||
MimeMessage replyMessage = new MimeMessage(emailSession); |
|
||||||
// replyMessage = (MimeMessage) message.reply(false);
|
|
||||||
replyMessage.setFrom(new InternetAddress(user)); |
|
||||||
replyMessage.setRecipients(Message.RecipientType.TO, recipient); |
|
||||||
replyMessage.setSubject(subject); |
|
||||||
replyMessage.setText(text); |
|
||||||
Transport t = emailSession.getTransport("smtp"); |
|
||||||
t.connect(user, password); |
|
||||||
t.sendMessage(replyMessage, replyMessage.getAllRecipients()); |
|
||||||
System.out.println("Message sent..."); |
|
||||||
} |
|
||||||
|
|
||||||
private static Session initSession(String pophost, String smtphost) { |
|
||||||
Properties properties = new Properties(); |
|
||||||
properties.put("mail.pop3.host", pophost); |
|
||||||
properties.put("mail.pop3.port", "995"); |
|
||||||
properties.put("mail.pop3.starttls.enable", "true"); |
|
||||||
properties.put("mail.smtp.auth", "true"); |
|
||||||
properties.put("mail.smtp.starttls.enable", "true"); |
|
||||||
properties.put("mail.smtp.host", smtphost); |
|
||||||
properties.put("mail.smtp.port", "25"); |
|
||||||
return Session.getDefaultInstance(properties); |
|
||||||
} |
|
||||||
|
|
||||||
public static void main(String[] args) { |
|
||||||
Session session = initSession("pop3.strato.de", "smtp.strato.de"); |
|
||||||
String username = "heartbeat@mbisping.de"; |
|
||||||
String password = "$Anfang1200"; |
|
||||||
|
|
||||||
try { |
|
||||||
check(session, username, password); |
|
||||||
send(session, username, "danielq@memtext.de", "From Düsseldorf with fun...", "This is the memtext's first digitial 'heartbeat' :-)\n send via java mail - \nThanks and see you around :-)", |
|
||||||
password); |
|
||||||
} catch (MessagingException e) { |
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace(); |
|
||||||
} catch (IOException e) { |
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace(); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
@ -1,293 +0,0 @@ |
|||||||
package de.memtext.hbt; |
|
||||||
|
|
||||||
import java.io.File; |
|
||||||
import java.io.FileOutputStream; |
|
||||||
import java.io.IOException; |
|
||||||
import java.io.InputStream; |
|
||||||
import java.sql.Connection; |
|
||||||
import java.sql.PreparedStatement; |
|
||||||
import java.sql.SQLException; |
|
||||||
import java.sql.Statement; |
|
||||||
import java.util.logging.Level; |
|
||||||
import java.util.regex.Matcher; |
|
||||||
import java.util.regex.Pattern; |
|
||||||
|
|
||||||
import javax.mail.BodyPart; |
|
||||||
import javax.mail.Flags; |
|
||||||
import javax.mail.Message; |
|
||||||
import javax.mail.MessagingException; |
|
||||||
import javax.mail.Multipart; |
|
||||||
import javax.mail.Part; |
|
||||||
import javax.mail.internet.AddressException; |
|
||||||
import javax.mail.internet.MimeMessage; |
|
||||||
|
|
||||||
import clover.com.atlassian.extras.common.org.springframework.util.StringUtils; |
|
||||||
import de.memtext.db.DbUtils; |
|
||||||
import de.memtext.util.FileUtils; |
|
||||||
import de.memtext.util.MailUtils; |
|
||||||
import de.superx.servlet.SuperXManager; |
|
||||||
import de.superx.servlet.SxMail; |
|
||||||
import de.superx.servlet.SxPools; |
|
||||||
|
|
||||||
public class NewHeartBeatAriel extends AbstractAriel { |
|
||||||
private static final Pattern pHbtId = Pattern.compile("@hbt:\\d*@"); |
|
||||||
|
|
||||||
public NewHeartBeatAriel(SxMail sxmail) throws IOException { |
|
||||||
this.sxmail = sxmail; |
|
||||||
initLogging(); |
|
||||||
} |
|
||||||
|
|
||||||
void processNewMessages(Message newMessages[]) throws MessagingException, IOException, SQLException { |
|
||||||
|
|
||||||
|
|
||||||
logger.log(Level.INFO," found " + newMessages.length + " new messages"); |
|
||||||
for (int i = 0, n = newMessages.length; i < n; i++) { |
|
||||||
Message aNewMessage = newMessages[i]; |
|
||||||
|
|
||||||
String content = MailUtils.getContent(aNewMessage); |
|
||||||
if (content.indexOf("@hbt:") == -1) |
|
||||||
createNewHeartBeat(aNewMessage, content); |
|
||||||
else |
|
||||||
appendToHeartBeat(aNewMessage, content); |
|
||||||
// had thought setting via inbox nessary, but that's only the preferred way to
|
|
||||||
// set flags for group of messages since some mail implementations by have
|
|
||||||
// optimized support for groups of messages
|
|
||||||
// inbox.setFlags(new Message[] {message}, , true);
|
|
||||||
// message.setFlags(flagsContainingOnlySeen, true);
|
|
||||||
// unseen wäre schöner, mailapi.jar aktualisieren bei HIS Antrag
|
|
||||||
// nötig,vielleicht klappt mit delete
|
|
||||||
aNewMessage.setFlag(Flags.Flag.DELETED, true); // AbstractAriel.run ruft sxmail.closeInbox() auf mit
|
|
||||||
// Anweisung zu löschen
|
|
||||||
|
|
||||||
// sorry to bother you, Garbage collector , need message only to times, hey or
|
|
||||||
// doesn't that matter anyway since only a simple reference (like in good old
|
|
||||||
// C), but clearer/easier to read if line Message message=.. was superfolous
|
|
||||||
|
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void appendToHeartBeat(Message message, String content) |
|
||||||
throws SQLException, IOException, MessagingException { |
|
||||||
StringBuffer result = new StringBuffer(); |
|
||||||
int hbtTid = -1; |
|
||||||
Connection con = SxPools.getConnection(sxmail.getMandantenID()); |
|
||||||
Statement stm = con.createStatement(); |
|
||||||
boolean isHbtFoundInDb = false; |
|
||||||
String feedbackSubject = ""; |
|
||||||
Matcher m = pHbtId.matcher(content); |
|
||||||
boolean foundHbtTag=m.find(); |
|
||||||
if (foundHbtTag) { |
|
||||||
String hbtIdString = content.substring(m.start() + 5, m.end() - 1); |
|
||||||
content=content.replaceAll("@hbt:\\d*@", ""); |
|
||||||
try { |
|
||||||
hbtTid = Integer.parseInt(hbtIdString); |
|
||||||
if (DbUtils.getInt(con, "select count(*) from hbt_heartbeat where tid=?", hbtTid) > 0) |
|
||||||
isHbtFoundInDb = true; |
|
||||||
} catch (NumberFormatException e) { |
|
||||||
result.append(" hbt:" + hbtIdString |
|
||||||
+ " konnte nicht in integer transformiert werden, Nachricht wird zwischengespeichert"); |
|
||||||
isHbtFoundInDb = false; |
|
||||||
} |
|
||||||
if (isHbtFoundInDb) { |
|
||||||
// TODO ggfs. mehrer Topics
|
|
||||||
int maxTopic = DbUtils.getInt(con, "select max(tid) from hbt_topic where hbt_id=?", hbtTid); |
|
||||||
// int maxNote = DbUtils.getInt(stm, "select max(tid) from hbt_note where
|
|
||||||
// hbt_id=" + hbtTid + " hbt_topic_id=" + maxTopic);
|
|
||||||
int newNoteId = createNote(con, stm, hbtTid, maxTopic, message, content); |
|
||||||
feedbackSubject = "Your new note was added to Heartbeat " + hbtTid; |
|
||||||
result.append("Feel free to view this HeartBeat by visiting " + sxmail.getWTFAI() |
|
||||||
+ "/edit/hbt/hbt_viewer.jsp?tid=" + hbtTid + " \n\n" + "Always at your service: \n" |
|
||||||
+ " your HeartBeatAriel @ SuperX"); |
|
||||||
|
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
if (!foundHbtTag || !isHbtFoundInDb) { |
|
||||||
feedbackSubject = "Sorry, target hbt found found ..."; |
|
||||||
PreparedStatement pst=con.prepareStatement("insert into hbt_tmp_note (note) values (?)"); |
|
||||||
pst.setString(1,content); |
|
||||||
pst.execute(); |
|
||||||
pst.close(); |
|
||||||
int newNoteId=DbUtils.getInt(stm, "select max(tid) from hbt_tmp_note"); |
|
||||||
result.append("you can select the right hbt_id by visiting " + sxmail.getWTFAI()+"/servlet/SuperXmlMaske?tid=60040?note_id="+newNoteId); |
|
||||||
} |
|
||||||
stm.close(); |
|
||||||
con.close(); |
|
||||||
sendFeedbackEmail(feedbackSubject, result.toString(), message); |
|
||||||
} |
|
||||||
|
|
||||||
private void createNewHeartBeat(Message inMessage, String content) |
|
||||||
throws SQLException, MessagingException, IOException { |
|
||||||
int newHbtTid = performHbtInsert(inMessage, content); |
|
||||||
String text = "Feel free to complete this heartbeat's details by visiting " + sxmail.getWTFAI() |
|
||||||
+ "/edit/hbt/hbt_edit.jsp?tid=" + newHbtTid + " \n\n" + "Always at your service: \n" |
|
||||||
+ " your HeartBeatAriel @ SuperX"; |
|
||||||
sendFeedbackEmail("Your new digital heartbeat has been created ...", text, inMessage); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Performs the creation of a new HeartBeat in the database |
|
||||||
* |
|
||||||
* @param message |
|
||||||
* @return newHbtTid |
|
||||||
* @throws SQLException |
|
||||||
* @throws MessagingException |
|
||||||
* @throws IOException |
|
||||||
*/ |
|
||||||
private int performHbtInsert(Message m, String content) throws SQLException, IOException, MessagingException { |
|
||||||
Connection con = SxPools.getConnection(sxmail.getMandantenID()); |
|
||||||
Statement stm = con.createStatement(); |
|
||||||
|
|
||||||
int newHbtTid = createHbt(con, stm, content, m.getSubject()); |
|
||||||
int newTopicId = createTopic(stm, newHbtTid); |
|
||||||
createNote(con, stm, newHbtTid, newTopicId, m, content); |
|
||||||
con.close(); |
|
||||||
return newHbtTid; |
|
||||||
} |
|
||||||
|
|
||||||
private int createHbt(Connection dbConnection, Statement stm, String content, String subject) |
|
||||||
throws IOException, MessagingException, SQLException { |
|
||||||
String primary_customer_id = identifyPrimaryCustomerId(dbConnection, stm, content); |
|
||||||
String name = StringUtils.replace(subject, "'", "''");// for SQL insert
|
|
||||||
// Sql insert - fuck prepared statements, nobody hacks this, I don't give a
|
|
||||||
// shit, not worth my extra time or effort, I want to get things done now while
|
|
||||||
// having fun :-)
|
|
||||||
stm.execute("select sp_update_sequence('hbt_heartbeat')"); |
|
||||||
String insertSql = "INSERT INTO hbt_heartbeat \n" + "( primary_customer_id,name," + " created_at, \n" |
|
||||||
+ " status \n" + ") \n" + "VALUES \n" + "( " + primary_customer_id + ",'" + name + "', " |
|
||||||
+ " today(), \n" + " 1 \n" + ") " + ""; |
|
||||||
stm.execute(insertSql); |
|
||||||
int newHbtTid = DbUtils.getInt(stm, "select max(tid) from hbt_heartbeat"); |
|
||||||
return newHbtTid; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* |
|
||||||
* Wenn im Text der weitergeleiteten Email der Absender mit @@ markiert ist, |
|
||||||
* z.B. @@hiber@his.de@@, diesen auslesen zugehörige Organisation auslesen |
|
||||||
* |
|
||||||
* @param m |
|
||||||
* @return String null oder key_apnr z.B. '1001' |
|
||||||
* @throws IOException |
|
||||||
* @throws MessagingException |
|
||||||
* @throws SQLException |
|
||||||
*/ |
|
||||||
private String identifyPrimaryCustomerId(Connection con, Statement stm, String content) |
|
||||||
throws IOException, MessagingException, SQLException { |
|
||||||
String result = "null"; |
|
||||||
int pos1 = content.indexOf("@@"); |
|
||||||
int pos2 = content.substring(pos1 + 2).indexOf("@@"); |
|
||||||
if (pos1 > -1 && pos2 > -1) { |
|
||||||
String absender = content.substring(pos1 + 2); |
|
||||||
absender = absender.substring(0, absender.lastIndexOf("@@")); |
|
||||||
logger.log(Level.INFO," checking customer " + absender); |
|
||||||
int userinfo_id = DbUtils.getInt(con, "select tid from userinfo where email=?", absender); |
|
||||||
result = DbUtils.getString(stm, |
|
||||||
"select min(ch110_institut) from user_institution where userid=" + userinfo_id); |
|
||||||
|
|
||||||
if (result == null) |
|
||||||
result = "null"; |
|
||||||
else |
|
||||||
result = "'" + result + "'"; |
|
||||||
} |
|
||||||
return result; |
|
||||||
} |
|
||||||
|
|
||||||
private int createTopic(Statement stm, int newHbtTid) throws SQLException { |
|
||||||
stm.execute("select sp_update_sequence('hbt_topic')"); |
|
||||||
String insertSql = "INSERT INTO hbt_topic \n" + "( hbt_id,name, created_at)" + "VALUES (" + newHbtTid |
|
||||||
+ ",'Start',now() )"; |
|
||||||
stm.execute(insertSql); |
|
||||||
int newTopicId = DbUtils.getInt(stm, "select max(tid) from hbt_topic"); |
|
||||||
return newTopicId; |
|
||||||
} |
|
||||||
|
|
||||||
private int createNote(Connection con, Statement stm, int hbtId, int topicId, Message m, String content) |
|
||||||
throws IOException, MessagingException, SQLException { |
|
||||||
stm.execute("select sp_update_sequence('hbt_note')"); |
|
||||||
PreparedStatement pst = con |
|
||||||
.prepareStatement(" INSERT INTO hbt_note (hbt_id,hbt_topic_id,note, created_at) VALUES (?,?,?,now());"); |
|
||||||
pst.setInt(1, hbtId); |
|
||||||
pst.setInt(2, topicId); |
|
||||||
|
|
||||||
pst.setString(3, content); |
|
||||||
pst.execute(); |
|
||||||
pst.close(); |
|
||||||
int newNoteId = DbUtils.getInt(stm, "select max(tid) from hbt_note"); |
|
||||||
saveAttachments(stm, hbtId, topicId, newNoteId, m); |
|
||||||
return newNoteId; |
|
||||||
} |
|
||||||
|
|
||||||
private void saveAttachments(Statement stm, int newHbtTid, int newTopicId, int newNoteId, Message m) |
|
||||||
throws IOException, MessagingException, SQLException { |
|
||||||
// List<String> attachments = new ArrayList<String>();
|
|
||||||
Object content = m.getContent(); |
|
||||||
// if (content instanceof String) return null;
|
|
||||||
|
|
||||||
if (content instanceof Multipart) { |
|
||||||
Multipart multipart = (Multipart) content; |
|
||||||
for (int i = 0; i < multipart.getCount(); i++) { |
|
||||||
BodyPart part = multipart.getBodyPart(i); |
|
||||||
logger.log(Level.INFO,part.getFileName() + " " + part.getContentType() + " " + part.getDisposition()); |
|
||||||
if (part.getDisposition() != null && part.getDisposition().equalsIgnoreCase(Part.ATTACHMENT)) { |
|
||||||
// result.addAll(getAttachments(multipart.getBodyPart(i)));
|
|
||||||
String filename = SuperXManager.getWEB_INFPfad()+"/downloads/hbt_"+newHbtTid+"_" +newNoteId+"_"+FileUtils.removeProblemChars(part.getFileName()); |
|
||||||
sxDownloadsInsert(stm, newHbtTid, newTopicId, newNoteId, filename, part.getContentType()); |
|
||||||
// javaxmail >1.4 bodyPart.saveFile(filename);
|
|
||||||
// old version
|
|
||||||
InputStream is = part.getInputStream(); |
|
||||||
File f = new File(filename); |
|
||||||
FileOutputStream fos = new FileOutputStream(f); |
|
||||||
byte[] buf = new byte[4096]; |
|
||||||
int bytesRead; |
|
||||||
while ((bytesRead = is.read(buf)) != -1) { |
|
||||||
fos.write(buf, 0, bytesRead); |
|
||||||
} |
|
||||||
fos.close(); |
|
||||||
logger.log(Level.INFO," saving attachment " + (i++) + " as " + filename); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
private void sxDownloadsInsert(Statement stm, int newHbtTid, int newTopicId, int newNoteId, String filename, |
|
||||||
String contenttype) throws SQLException { |
|
||||||
stm.execute("select sp_update_sequence('sx_downloads')"); |
|
||||||
String filenameShort = filename.substring(filename.indexOf(File.separator + "hbt") + 1); |
|
||||||
String insertSQLSxDownloads = "INSERT INTO sx_downloads \n" + "( \n" + " name, \n" + " importdatum, \n" |
|
||||||
+ " kommentar, \n" + " kommentar_url, \n" + " contenttype, \n" + " datei, \n" + " gueltig_seit, \n" |
|
||||||
+ " gueltig_bis \n" + ") \n" + "VALUES \n" + "( \n" + " '" + filenameShort + "', \n" + " today(), \n" |
|
||||||
+ " 'kommentar_value', \n" + " 'kommentar_url_value', \n" + " '" + contenttype + "', \n" + " '" |
|
||||||
+ filenameShort + "', \n" + " today(), \n" + " date_val('1.1.3000') \n" + ") \n" + ""; |
|
||||||
stm.execute(insertSQLSxDownloads); |
|
||||||
int newDownloadTid = DbUtils.getInt(stm, "select max(tid) from sx_downloads"); |
|
||||||
stm.executeUpdate("insert into hbt_attachment (hbt_id,topic_id,note_id,download_id) values (" + newHbtTid + "," |
|
||||||
+ newTopicId + "," + newNoteId + "," + newDownloadTid + ")"); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* sendFeedBackEmail -- hier hätte ich gern automatisch newline in Zeile 60 |
|
||||||
* direkt unter createNewHeartBeat automatisch erzeugt, dann nach weiter unten |
|
||||||
* im Quelltext verlagert, damit von der Reihenfolge in |
|
||||||
* createNewHeartBeat(Message message) her passt |
|
||||||
* |
|
||||||
* @param newHbtTid : tid von neuem HeartBeat in der Datenbank |
|
||||||
* @param inMessage |
|
||||||
* @throws MessagingException |
|
||||||
* @throws AddressException |
|
||||||
*/ |
|
||||||
private void sendFeedbackEmail(String subject, String text, Message inMessage) |
|
||||||
throws AddressException, MessagingException { |
|
||||||
MimeMessage reply = sxmail.createMessage(); |
|
||||||
reply.setRecipients(Message.RecipientType.TO, inMessage.getFrom()); |
|
||||||
reply.setSubject(subject); |
|
||||||
reply.setText(text); |
|
||||||
sxmail.setMessage(reply); |
|
||||||
|
|
||||||
logger.log(Level.INFO,"Reply message happily sent..."); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
} |
|
||||||
@ -1,10 +1,11 @@ |
|||||||
package de.memtext.icons; |
package de.memtext.icons; |
||||||
|
|
||||||
import java.awt.Graphics; |
import java.awt.Graphics; |
||||||
|
|
||||||
public class ArrowDownIcon extends BasicIcon { |
public class ArrowDownIcon extends BasicIcon { |
||||||
public void myPaint(Graphics g) { |
@Override |
||||||
drawArrowDown(g, 6); |
public void myPaint(Graphics g) { |
||||||
} |
drawArrowDown(g, 6); |
||||||
|
} |
||||||
} |
|
||||||
|
} |
||||||
|
|||||||
@ -1,13 +1,14 @@ |
|||||||
package de.memtext.icons; |
package de.memtext.icons; |
||||||
|
|
||||||
import java.awt.Graphics; |
import java.awt.Graphics; |
||||||
|
|
||||||
public class ArrowRight extends BasicIcon { |
public class ArrowRight extends BasicIcon { |
||||||
|
|
||||||
void myPaint(Graphics g) { |
@Override |
||||||
drawArrowRight(g); |
void myPaint(Graphics g) { |
||||||
} |
drawArrowRight(g); |
||||||
|
} |
||||||
} |
|
||||||
|
} |
||||||
|
|
||||||
//Created on 17.04.2004 at 21:42:08
|
//Created on 17.04.2004 at 21:42:08
|
||||||
@ -1,14 +1,15 @@ |
|||||||
package de.memtext.icons; |
package de.memtext.icons; |
||||||
|
|
||||||
import java.awt.Graphics; |
import java.awt.Graphics; |
||||||
|
|
||||||
import javax.swing.Icon; |
import javax.swing.Icon; |
||||||
|
|
||||||
public class ArrowUpIcon extends BasicIcon implements Icon { |
public class ArrowUpIcon extends BasicIcon implements Icon { |
||||||
|
|
||||||
public void myPaint(Graphics g) { |
@Override |
||||||
drawArrowUp(g, 4); |
public void myPaint(Graphics g) { |
||||||
|
drawArrowUp(g, 4); |
||||||
} |
|
||||||
|
} |
||||||
} |
|
||||||
|
} |
||||||
|
|||||||
@ -1,99 +1,109 @@ |
|||||||
package de.memtext.icons; |
package de.memtext.icons; |
||||||
|
|
||||||
import java.awt.Color; |
import java.awt.Color; |
||||||
import java.awt.Component; |
import java.awt.Component; |
||||||
import java.awt.Graphics; |
import java.awt.Graphics; |
||||||
|
|
||||||
import javax.swing.Icon; |
import javax.swing.Icon; |
||||||
import javax.swing.JButton; |
import javax.swing.JButton; |
||||||
|
|
||||||
public abstract class BasicIcon implements Icon { |
public abstract class BasicIcon implements Icon { |
||||||
private int iconWidth = 16, iconHeight = 16; |
private int iconWidth = 16, iconHeight = 16; |
||||||
private Color color = Color.black; |
|
||||||
/** |
private Color color = Color.black; |
||||||
* @see javax.swing.Icon#getIconWidth() |
|
||||||
*/ |
/** |
||||||
public int getIconWidth() { |
* @see javax.swing.Icon#getIconWidth() |
||||||
return iconWidth; |
*/ |
||||||
} |
@Override |
||||||
|
public int getIconWidth() { |
||||||
/** |
return iconWidth; |
||||||
* @see javax.swing.Icon#getIconHeight() |
} |
||||||
*/ |
|
||||||
public int getIconHeight() { |
/** |
||||||
return iconHeight; |
* @see javax.swing.Icon#getIconHeight() |
||||||
} |
*/ |
||||||
public void paintIcon(Component c, Graphics g, int x, int y) { |
@Override |
||||||
g.translate(x, y); |
public int getIconHeight() { |
||||||
if (c.isEnabled()) |
return iconHeight; |
||||||
g.setColor(color); |
} |
||||||
else |
|
||||||
g.setColor(Color.GRAY); |
@Override |
||||||
myPaint(g); |
public void paintIcon(Component c, Graphics g, int x, int y) { |
||||||
g.translate(-x, -y); |
g.translate(x, y); |
||||||
} |
if (c.isEnabled()) |
||||||
abstract void myPaint(Graphics g); |
g.setColor(color); |
||||||
void drawDoubleLine(Graphics g, int y) { |
else |
||||||
if (y > getIconHeight() - 2) |
g.setColor(Color.GRAY); |
||||||
throw new IllegalArgumentException("can't draw that low"); |
myPaint(g); |
||||||
g.drawLine(0, y, getIconWidth(), y); |
g.translate(-x, -y); |
||||||
g.drawLine(0, y + 1, getIconWidth(), y + 1); |
} |
||||||
} |
|
||||||
|
abstract void myPaint(Graphics g); |
||||||
void drawArrowRight(Graphics g) { |
|
||||||
int midx = (int) Math.floor(getIconWidth() / 2); |
void drawDoubleLine(Graphics g, int y) { |
||||||
int midy = (int) Math.floor(getIconHeight() / 2); |
if (y > getIconHeight() - 2) throw new IllegalArgumentException("can't draw that low"); |
||||||
// mittellinie
|
g.drawLine(0, y, getIconWidth(), y); |
||||||
g.drawLine(0, midy - 1, getIconWidth(), midy - 1); |
g.drawLine(0, y + 1, getIconWidth(), y + 1); |
||||||
g.drawLine(0, midy, getIconWidth(), midy); |
} |
||||||
g.drawLine(0, midy + 1, getIconWidth(), midy + 1); |
|
||||||
|
void drawArrowRight(Graphics g) { |
||||||
g.drawLine(midx + 1, 1, getIconWidth(), midy - 1); |
int midx = (int) Math.floor(getIconWidth() / 2); |
||||||
g.drawLine(midx + 1, 2, getIconWidth(), midy); |
int midy = (int) Math.floor(getIconHeight() / 2); |
||||||
|
// mittellinie
|
||||||
g.drawLine(midx + 1, getIconHeight() - 1, getIconWidth(), midy + 1); |
g.drawLine(0, midy - 1, getIconWidth(), midy - 1); |
||||||
g.drawLine(midx + 1, getIconHeight() - 2, getIconWidth(), midy); |
g.drawLine(0, midy, getIconWidth(), midy); |
||||||
|
g.drawLine(0, midy + 1, getIconWidth(), midy + 1); |
||||||
} |
|
||||||
|
g.drawLine(midx + 1, 1, getIconWidth(), midy - 1); |
||||||
void drawArrowUp(Graphics g, int y) { |
g.drawLine(midx + 1, 2, getIconWidth(), midy); |
||||||
int midx = (int) Math.floor(getIconWidth() / 2); |
|
||||||
int midy = (int) Math.floor(getIconHeight() / 2); |
g.drawLine(midx + 1, getIconHeight() - 1, getIconWidth(), midy + 1); |
||||||
g.drawLine(0, y + midy, midx, y); |
g.drawLine(midx + 1, getIconHeight() - 2, getIconWidth(), midy); |
||||||
g.drawLine(midx, y, getIconWidth(), y + midy); |
|
||||||
g.drawLine(0, y + midy + 1, midx, y + 1); |
} |
||||||
g.drawLine(midx, y + 1, getIconWidth(), y + midy + 1); |
|
||||||
|
void drawArrowUp(Graphics g, int y) { |
||||||
} |
int midx = (int) Math.floor(getIconWidth() / 2); |
||||||
void drawArrowDown(Graphics g, int y) { |
int midy = (int) Math.floor(getIconHeight() / 2); |
||||||
int midx = (int) Math.floor(getIconWidth() / 2); |
g.drawLine(0, y + midy, midx, y); |
||||||
int midy = (int) Math.floor(getIconHeight() / 2); |
g.drawLine(midx, y, getIconWidth(), y + midy); |
||||||
g.drawLine(0, y, midx, midy + y); |
g.drawLine(0, y + midy + 1, midx, y + 1); |
||||||
g.drawLine(midx, y + midy, getIconWidth(), y); |
g.drawLine(midx, y + 1, getIconWidth(), y + midy + 1); |
||||||
g.drawLine(0, y + 1, midx, midy + y + 1); |
|
||||||
g.drawLine(midx, y + midy + 1, getIconWidth(), y + 1); |
} |
||||||
|
|
||||||
} |
void drawArrowDown(Graphics g, int y) { |
||||||
public static void main(String[] args) { |
int midx = (int) Math.floor(getIconWidth() / 2); |
||||||
de.memtext.widgets.MBFrame f = new de.memtext.widgets.MBFrame("test"); |
int midy = (int) Math.floor(getIconHeight() / 2); |
||||||
f.setCenter(new JButton("test", new ArrowRight())); |
g.drawLine(0, y, midx, midy + y); |
||||||
f.pack(); |
g.drawLine(midx, y + midy, getIconWidth(), y); |
||||||
f.show(); |
g.drawLine(0, y + 1, midx, midy + y + 1); |
||||||
} |
g.drawLine(midx, y + midy + 1, getIconWidth(), y + 1); |
||||||
public void setIconHeight(int i) { |
|
||||||
iconHeight = i; |
} |
||||||
} |
|
||||||
|
public static void main(String[] args) { |
||||||
public void setIconWidth(int i) { |
de.memtext.widgets.MBFrame f = new de.memtext.widgets.MBFrame("test"); |
||||||
iconWidth = i; |
f.setCenter(new JButton("test", new ArrowRight())); |
||||||
} |
f.pack(); |
||||||
|
f.show(); |
||||||
public Color getColor() { |
} |
||||||
return color; |
|
||||||
} |
public void setIconHeight(int i) { |
||||||
|
iconHeight = i; |
||||||
public void setColor(Color color) { |
} |
||||||
this.color = color; |
|
||||||
} |
public void setIconWidth(int i) { |
||||||
|
iconWidth = i; |
||||||
} |
} |
||||||
|
|
||||||
|
public Color getColor() { |
||||||
|
return color; |
||||||
|
} |
||||||
|
|
||||||
|
public void setColor(Color color) { |
||||||
|
this.color = color; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|||||||
@ -1,16 +1,16 @@ |
|||||||
package de.memtext.icons; |
package de.memtext.icons; |
||||||
|
|
||||||
import java.awt.Graphics; |
import java.awt.Graphics; |
||||||
|
|
||||||
|
|
||||||
public class DoubleArrowDownIcon extends BasicIcon { |
public class DoubleArrowDownIcon extends BasicIcon { |
||||||
public void myPaint(Graphics g) |
@Override |
||||||
{ |
public void myPaint(Graphics g) { |
||||||
drawArrowDown(g,2); |
drawArrowDown(g, 2); |
||||||
drawArrowDown(g,6); |
drawArrowDown(g, 6); |
||||||
|
|
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
|
|||||||
@ -1,23 +1,23 @@ |
|||||||
package de.memtext.icons; |
package de.memtext.icons; |
||||||
|
|
||||||
import java.awt.Graphics; |
import java.awt.Graphics; |
||||||
|
|
||||||
/** |
/** |
||||||
* @author MB |
* @author MB |
||||||
* |
* |
||||||
* To change this generated comment edit the template variable "typecomment": |
* To change this generated comment edit the template variable "typecomment": |
||||||
* Window>Preferences>Java>Templates. |
* Window>Preferences>Java>Templates. |
||||||
* To enable and disable the creation of type comments go to |
* To enable and disable the creation of type comments go to |
||||||
* Window>Preferences>Java>Code Generation. |
* Window>Preferences>Java>Code Generation. |
||||||
*/ |
*/ |
||||||
public class DoubleArrowDownLineIcon extends BasicIcon { |
public class DoubleArrowDownLineIcon extends BasicIcon { |
||||||
public void myPaint(Graphics g) |
@Override |
||||||
{ |
public void myPaint(Graphics g) { |
||||||
drawArrowDown(g,0); |
drawArrowDown(g, 0); |
||||||
drawArrowDown(g,4); |
drawArrowDown(g, 4); |
||||||
drawDoubleLine(g,getIconHeight()-2); |
drawDoubleLine(g, getIconHeight() - 2); |
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
|
|||||||
@ -1,22 +1,22 @@ |
|||||||
package de.memtext.icons; |
package de.memtext.icons; |
||||||
|
|
||||||
import java.awt.Graphics; |
import java.awt.Graphics; |
||||||
|
|
||||||
/** |
/** |
||||||
* @author MB |
* @author MB |
||||||
* |
* |
||||||
* To change this generated comment edit the template variable "typecomment": |
* To change this generated comment edit the template variable "typecomment": |
||||||
* Window>Preferences>Java>Templates. |
* Window>Preferences>Java>Templates. |
||||||
* To enable and disable the creation of type comments go to |
* To enable and disable the creation of type comments go to |
||||||
* Window>Preferences>Java>Code Generation. |
* Window>Preferences>Java>Code Generation. |
||||||
*/ |
*/ |
||||||
public class DoubleArrowUpIcon extends BasicIcon { |
public class DoubleArrowUpIcon extends BasicIcon { |
||||||
public void myPaint(Graphics g) |
@Override |
||||||
{ |
public void myPaint(Graphics g) { |
||||||
drawArrowUp(g,0); |
drawArrowUp(g, 0); |
||||||
drawArrowUp(g,4); |
drawArrowUp(g, 4); |
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
|
|||||||
@ -1,23 +1,23 @@ |
|||||||
package de.memtext.icons; |
package de.memtext.icons; |
||||||
|
|
||||||
import java.awt.Graphics; |
import java.awt.Graphics; |
||||||
|
|
||||||
/** |
/** |
||||||
* @author MB |
* @author MB |
||||||
* |
* |
||||||
* To change this generated comment edit the template variable "typecomment": |
* To change this generated comment edit the template variable "typecomment": |
||||||
* Window>Preferences>Java>Templates. |
* Window>Preferences>Java>Templates. |
||||||
* To enable and disable the creation of type comments go to |
* To enable and disable the creation of type comments go to |
||||||
* Window>Preferences>Java>Code Generation. |
* Window>Preferences>Java>Code Generation. |
||||||
*/ |
*/ |
||||||
public class DoubleArrowUpLineIcon extends BasicIcon { |
public class DoubleArrowUpLineIcon extends BasicIcon { |
||||||
public void myPaint(Graphics g) |
@Override |
||||||
{ |
public void myPaint(Graphics g) { |
||||||
drawDoubleLine(g,0); |
drawDoubleLine(g, 0); |
||||||
drawArrowUp(g,2); |
drawArrowUp(g, 2); |
||||||
drawArrowUp(g,6); |
drawArrowUp(g, 6); |
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
|
|||||||
@ -1,101 +1,99 @@ |
|||||||
package de.memtext.icons; |
package de.memtext.icons; |
||||||
|
|
||||||
import javax.swing.ImageIcon; |
import javax.swing.ImageIcon; |
||||||
|
|
||||||
import de.memtext.util.IconUtils; |
import de.memtext.util.IconUtils; |
||||||
|
|
||||||
/** |
/** |
||||||
* @author MB |
* @author MB |
||||||
* |
* |
||||||
changed xxx |
changed xxx |
||||||
*/ |
*/ |
||||||
public class MBStandardIcons { |
public class MBStandardIcons { |
||||||
private static ImageIcon indexBox, |
private static ImageIcon indexBox, newDoc, copyWin, searchWin, viewingGlass, table, delete, properties; |
||||||
newDoc, |
|
||||||
copyWin, |
private static ClassLoader cl; |
||||||
searchWin, |
|
||||||
viewingGlass, |
/** |
||||||
table, |
* Constructor for StandardIcons. |
||||||
delete, |
*/ |
||||||
properties; |
private MBStandardIcons() { |
||||||
private static ClassLoader cl; |
|
||||||
/** |
} |
||||||
* Constructor for StandardIcons. |
|
||||||
*/ |
public static ImageIcon get(String name) { |
||||||
private MBStandardIcons() { |
return IconUtils.get("de/memtext/icons/" + name); |
||||||
|
} |
||||||
} |
|
||||||
public static ImageIcon get(String name) { |
static { |
||||||
return IconUtils.get("de/memtext/icons/" + name); |
MBStandardIcons s = new MBStandardIcons(); |
||||||
} |
cl = s.getClass().getClassLoader(); |
||||||
static { |
copyWin = new ImageIcon(cl.getResource("de/memtext/icons/copyWindows.gif")); |
||||||
MBStandardIcons s = new MBStandardIcons(); |
searchWin = new ImageIcon(cl.getResource("de/memtext/icons/searchWindows.gif")); |
||||||
cl = s.getClass().getClassLoader(); |
viewingGlass = new ImageIcon(cl.getResource("de/memtext/icons/viewingGlass.gif")); |
||||||
copyWin = |
table = new ImageIcon(cl.getResource("de/memtext/icons/table.gif")); |
||||||
new ImageIcon(cl.getResource("de/memtext/icons/copyWindows.gif")); |
newDoc = new ImageIcon(cl.getResource("de/memtext/icons/newDoc.gif")); |
||||||
searchWin = |
delete = new ImageIcon(cl.getResource("de/memtext/icons/delete.gif")); |
||||||
new ImageIcon(cl.getResource("de/memtext/icons/searchWindows.gif")); |
properties = new ImageIcon(cl.getResource("de/memtext/icons/properties.gif")); |
||||||
viewingGlass = |
indexBox = new ImageIcon(cl.getResource("de/memtext/icons/indexBox.gif")); |
||||||
new ImageIcon(cl.getResource("de/memtext/icons/viewingGlass.gif")); |
} |
||||||
table = new ImageIcon(cl.getResource("de/memtext/icons/table.gif")); |
|
||||||
newDoc = new ImageIcon(cl.getResource("de/memtext/icons/newDoc.gif")); |
public static ImageIcon getEntry() { |
||||||
delete = new ImageIcon(cl.getResource("de/memtext/icons/delete.gif")); |
return new ImageIcon(cl.getResource("de/memtext/icons/entry.gif")); |
||||||
properties = |
} |
||||||
new ImageIcon(cl.getResource("de/memtext/icons/properties.gif")); |
|
||||||
indexBox = |
public static ImageIcon getCopy() { |
||||||
new ImageIcon(cl.getResource("de/memtext/icons/indexBox.gif")); |
return copyWin; |
||||||
} |
} |
||||||
public static ImageIcon getEntry() { |
|
||||||
return new ImageIcon(cl.getResource("de/memtext/icons/entry.gif")); |
public static ImageIcon getSearch() { |
||||||
} |
return searchWin; |
||||||
public static ImageIcon getCopy() { |
} |
||||||
return copyWin; |
|
||||||
} |
public static ImageIcon getDelete() { |
||||||
public static ImageIcon getSearch() { |
return delete; |
||||||
return searchWin; |
} |
||||||
} |
|
||||||
public static ImageIcon getDelete() { |
public static ImageIcon getPrint() { |
||||||
return delete; |
return new ImageIcon(cl.getResource("de/memtext/icons/print.gif")); |
||||||
} |
|
||||||
public static ImageIcon getPrint() |
|
||||||
{ |
} |
||||||
return new ImageIcon(cl.getResource("de/memtext/icons/print.gif")); |
|
||||||
|
public static ImageIcon getProperties() { |
||||||
|
return properties; |
||||||
} |
} |
||||||
public static ImageIcon getProperties() { |
|
||||||
return properties; |
/** |
||||||
} |
* Returns the table. |
||||||
/** |
* @return ImageIcon |
||||||
* Returns the table. |
*/ |
||||||
* @return ImageIcon |
public static ImageIcon getTable() { |
||||||
*/ |
return table; |
||||||
public static ImageIcon getTable() { |
} |
||||||
return table; |
|
||||||
} |
/** |
||||||
|
* Returns the viewingGlass. |
||||||
/** |
* @return ImageIcon |
||||||
* Returns the viewingGlass. |
*/ |
||||||
* @return ImageIcon |
public static ImageIcon getViewingGlass() { |
||||||
*/ |
return viewingGlass; |
||||||
public static ImageIcon getViewingGlass() { |
} |
||||||
return viewingGlass; |
|
||||||
} |
/** |
||||||
|
* Returns the newDoc. |
||||||
/** |
* @return ImageIcon |
||||||
* Returns the newDoc. |
*/ |
||||||
* @return ImageIcon |
public static ImageIcon getNewDoc() { |
||||||
*/ |
return newDoc; |
||||||
public static ImageIcon getNewDoc() { |
} |
||||||
return newDoc; |
|
||||||
} |
/** |
||||||
|
* Returns the indexBox. |
||||||
/** |
* @return ImageIcon |
||||||
* Returns the indexBox. |
*/ |
||||||
* @return ImageIcon |
public static ImageIcon getIndexBox() { |
||||||
*/ |
return indexBox; |
||||||
public static ImageIcon getIndexBox() { |
} |
||||||
return indexBox; |
|
||||||
} |
} |
||||||
|
|
||||||
} |
|
||||||
|
|||||||
@ -1,28 +0,0 @@ |
|||||||
package de.memtext.lang; |
|
||||||
public class SingOrPluralWord { |
|
||||||
public final static SingOrPluralWord SEIN=new SingOrPluralWord("ist","sind"); |
|
||||||
private int count; |
|
||||||
private String singular,plural; |
|
||||||
public SingOrPluralWord(String singular,String plural) { |
|
||||||
this.singular=singular; |
|
||||||
this.plural=plural; |
|
||||||
} |
|
||||||
|
|
||||||
public static String format(int count,String sing,String plural) |
|
||||||
{ |
|
||||||
if (count==1) return count+" "+sing; |
|
||||||
else |
|
||||||
return count+" "+plural; |
|
||||||
} |
|
||||||
|
|
||||||
public String say(int count) |
|
||||||
{ |
|
||||||
if (count==1) return singular; |
|
||||||
else |
|
||||||
return plural; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
//Created on 12.12.2003 at 15:53:43
|
|
||||||
@ -1,32 +1,37 @@ |
|||||||
package de.memtext.observ; |
package de.memtext.observ; |
||||||
|
|
||||||
import javax.swing.event.DocumentEvent; |
import javax.swing.event.DocumentEvent; |
||||||
import javax.swing.event.DocumentListener; |
import javax.swing.event.DocumentListener; |
||||||
/** |
|
||||||
* A document listener that will inform an observable about changes |
/** |
||||||
* in the document |
* A document listener that will inform an observable about changes |
||||||
*/ |
* in the document |
||||||
public class DocumentListenerObserver implements DocumentListener { |
*/ |
||||||
private MyObservable observable; |
public class DocumentListenerObserver implements DocumentListener { |
||||||
public DocumentListenerObserver(MyObservable observable) { |
private MyObservable observable; |
||||||
this.observable= observable; |
|
||||||
} |
public DocumentListenerObserver(MyObservable observable) { |
||||||
|
this.observable = observable; |
||||||
public void insertUpdate(DocumentEvent e) { |
} |
||||||
observable.markChanged(); |
|
||||||
observable.notifyObservers(); |
@Override |
||||||
} |
public void insertUpdate(DocumentEvent e) { |
||||||
|
observable.markChanged(); |
||||||
public void removeUpdate(DocumentEvent e) { |
observable.notifyObservers(); |
||||||
observable.markChanged(); |
} |
||||||
observable.notifyObservers(); |
|
||||||
} |
@Override |
||||||
|
public void removeUpdate(DocumentEvent e) { |
||||||
public void changedUpdate(DocumentEvent e) { |
observable.markChanged(); |
||||||
observable.markChanged(); |
observable.notifyObservers(); |
||||||
observable.notifyObservers(); |
} |
||||||
} |
|
||||||
|
@Override |
||||||
} |
public void changedUpdate(DocumentEvent e) { |
||||||
|
observable.markChanged(); |
||||||
|
observable.notifyObservers(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
//Created on 19.04.2004 at 18:30:30
|
//Created on 19.04.2004 at 18:30:30
|
||||||
@ -1,17 +1,17 @@ |
|||||||
package de.memtext.observ; |
package de.memtext.observ; |
||||||
|
|
||||||
import java.io.Serializable; |
import java.io.Serializable; |
||||||
import java.util.Observable; |
import java.util.Observable; |
||||||
|
|
||||||
/** |
/** |
||||||
* Rather silly, but for some reason Java complained |
* Rather silly, but for some reason Java complained |
||||||
* that the setChanged() method was not visible |
* that the setChanged() method was not visible |
||||||
*/ |
*/ |
||||||
|
|
||||||
public class MyObservable extends Observable implements Serializable { |
public class MyObservable extends Observable implements Serializable { |
||||||
|
|
||||||
public void markChanged() { |
public void markChanged() { |
||||||
super.setChanged(); |
super.setChanged(); |
||||||
} |
} |
||||||
|
|
||||||
} |
} |
||||||
|
|||||||
@ -1,9 +1,9 @@ |
|||||||
package de.memtext.rights; |
package de.memtext.rights; |
||||||
|
|
||||||
public interface Allowable { |
public interface Allowable { |
||||||
public boolean isAllowed(); |
public boolean isAllowed(); |
||||||
|
|
||||||
public void setAllowed(boolean b); |
public void setAllowed(boolean b); |
||||||
} |
} |
||||||
|
|
||||||
//Created on 24.04.2005 at 07:45:25
|
//Created on 24.04.2005 at 07:45:25
|
||||||
|
|||||||
@ -1,12 +1,12 @@ |
|||||||
package de.memtext.rights; |
package de.memtext.rights; |
||||||
|
|
||||||
public interface AllowableHierarchy extends Allowable { |
public interface AllowableHierarchy extends Allowable { |
||||||
/** |
/** |
||||||
* @returns true if node itself or any of descendants is allowed |
* @returns true if node itself or any of descendants is allowed |
||||||
*/ |
*/ |
||||||
public boolean isAnyDescendantAllowed(); |
public boolean isAnyDescendantAllowed(); |
||||||
|
|
||||||
public void setDescendantsAllowed(boolean b); |
public void setDescendantsAllowed(boolean b); |
||||||
} |
} |
||||||
|
|
||||||
//Created on 24.04.2005 at 07:54:08
|
//Created on 24.04.2005 at 07:54:08
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue