Ontimize 5.2072EN

com.ontimize.gui.field.document
Class CIFDocument

java.lang.Object
  extended byjavax.swing.text.AbstractDocument
      extended byjavax.swing.text.PlainDocument
          extended bycom.ontimize.gui.field.document.MaskDocument
              extended bycom.ontimize.gui.field.document.CIFDocument
All Implemented Interfaces:
javax.swing.text.Document, java.io.Serializable

public class CIFDocument
extends MaskDocument

Implements the document model to insert a CIFs into a JTextField

Version:
1.0 01/04/2001
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.text.AbstractDocument
javax.swing.text.AbstractDocument.AbstractElement, javax.swing.text.AbstractDocument.AttributeContext, javax.swing.text.AbstractDocument.BranchElement, javax.swing.text.AbstractDocument.Content, javax.swing.text.AbstractDocument.DefaultDocumentEvent, javax.swing.text.AbstractDocument.ElementEdit, javax.swing.text.AbstractDocument.LeafElement
 
Field Summary
 
Fields inherited from class com.ontimize.gui.field.document.MaskDocument
exactMatch, mask
 
Fields inherited from class javax.swing.text.PlainDocument
lineLimitAttribute, tabSizeAttribute
 
Fields inherited from class javax.swing.text.AbstractDocument
BAD_LOCATION, BidiElementName, ContentElementName, ElementNameAttribute, listenerList, ParagraphElementName, SectionElementName
 
Fields inherited from interface javax.swing.text.Document
StreamDescriptionProperty, TitleProperty
 
Constructor Summary
CIFDocument()
          Constructor.
 
Method Summary
static char calculateLetter(int number)
           
static char calculateNumber(int number)
           
 void insertString(int offset, java.lang.String stringValue, javax.swing.text.AttributeSet attributes)
          Text insertion with input validations
static boolean isCIFWellFormed(java.lang.String CIF)
          CIF VALIDATION.
 
Methods inherited from class com.ontimize.gui.field.document.MaskDocument
compareToMask, getValue, isFixedChar, isRight, setExactMatch, setValue
 
Methods inherited from class javax.swing.text.PlainDocument
createDefaultRoot, getDefaultRootElement, getParagraphElement, insertUpdate, removeUpdate
 
Methods inherited from class javax.swing.text.AbstractDocument
addDocumentListener, addUndoableEditListener, createBranchElement, createLeafElement, createPosition, dump, fireChangedUpdate, fireInsertUpdate, fireRemoveUpdate, fireUndoableEditUpdate, getAsynchronousLoadPriority, getAttributeContext, getBidiRootElement, getContent, getCurrentWriter, getDocumentFilter, getDocumentListeners, getDocumentProperties, getEndPosition, getLength, getListeners, getProperty, getRootElements, getStartPosition, getText, getText, getUndoableEditListeners, postRemoveUpdate, putProperty, readLock, readUnlock, remove, removeDocumentListener, removeUndoableEditListener, render, replace, setAsynchronousLoadPriority, setDocumentFilter, setDocumentProperties, writeLock, writeUnlock
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CIFDocument

public CIFDocument()
Constructor. Uses the #MaskDocument constructor, with the correct mask to insert the CIF, this is: A0000000%

Method Detail

insertString

public void insertString(int offset,
                         java.lang.String stringValue,
                         javax.swing.text.AttributeSet attributes)
Text insertion with input validations

Specified by:
insertString in interface javax.swing.text.Document
Overrides:
insertString in class MaskDocument

calculateLetter

public static char calculateLetter(int number)

calculateNumber

public static char calculateNumber(int number)

isCIFWellFormed

public static boolean isCIFWellFormed(java.lang.String CIF)
CIF VALIDATION.
1) First letter can be: A, B, C, D, E, F, G, H, N, P, Q, S, J ,U ,V, W, R.
A - Public corporation / Public limited company
B - Limited corporation / Limited company
C - Association / Collective corporation
D - Partnership
E - Co - ownership
F - Cooperatives
G - Associations and other not defined types
H - Home owners associations
J - Civil corporations
U - Temporal companies association
V - Not defined types
N - Foreign entity
W - Permanent establishment of non-resident entity in Spanish territory
Q - Public corporations
R - Religious corporations S - State and autonomous regions administration organisms
P - Local corporations

2) Validation algorithm
1 - Remove the first and the last character in the CIF (first letter and control character), this return a string with 7 digits.
2- Sum all digits in even position, getting a result whose name will be A
3- For each digit in a odd position multiply it by 2, sum the result digits and store this value whose name will be B.
4- Sum A and B getting the result C.
5 - Get the units digit of C and subtract it from 10 (10 - C units digit) getting D.
6 - Using this result D is possible to obtain the control character. If control character must be a numeric value, this is directly D. If control character must be a letter the equivalence is 1-->A, 1 -->B etc.

EXAMPLE: CIF: "A58818501"
Remove first and last character getting "5881854"
Sum the even digits: A = 8 + 1 + 5 = 14
With the odd positions multiply by 2 and sum the result digits:
5 * 2 = 10 ==> 1 + 0 = 1
8 * 2 = 16 ==> 1 + 6 = 7
8 * 2 = 16 ==> 1 + 6 = 7
0 * 2 = 0 ==> 0
B = 1 + 7 + 7 = 15
C = A + B = 14 + 15 = 29
The units digit of C is 9. Abstract this value from 10 getting 10 - 9 = 1
If control character is a letter this is "A". If must be a number is directly 1.
In this example CIF values starts with C and all CIF with C uses a numeric control character.
In case of result = 10 - 0, the validation number will be ZERO or the letter J

Parameters:
CIF -
Returns:

Ontimize